Intersects, Overlaps and Touches not implemented!? How can i do this?

Mar 29, 2010 at 3:15 PM

 

        /// <summary>
        /// Returns true if there is any intersection between the two geometries.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Intersects(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// Returns true if the intersection of the two geometries results in an object of the same dimension as the
        /// input geometries and the intersection geometry is not equal to either geometry.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Overlaps(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// Returns true if the only points in common between the two geometries lie in the union of their boundaries.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Touches(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }
How can i execute intersections?  
I need to use Net Topology?
        /// <summary>
        /// Returns true if there is any intersection between the two geometries.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Intersects(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns true if the intersection of the two geometries results in an object of the same dimension as the
        /// input geometries and the intersection geometry is not equal to either geometry.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Overlaps(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Returns true if the only points in common between the two geometries lie in the union of their boundaries.
        /// </summary>
        /// <param name="g1"></param>
        /// <param name="g2"></param>
        /// <returns></returns>
        public static bool Touches(Geometry g1, Geometry g2)
        {
            throw new NotImplementedException();
        }

 

 

Coordinator
Mar 29, 2010 at 3:32 PM

Hi Sandex, yes you should use NTS for geometry and topology functions. cheers jd

Mar 29, 2010 at 5:06 PM

Ok perfect!  i've done a check for northen and souther bound..    because otherwise for Mercator projection i got invalid points....  (too close to the poles)...

 

          if (ntsGeometry.Intersects(_northerWorldBound))
            {
                Console.WriteLine(name + " must be truncated @ North");
                //must be truncated @ North
                return Geometry.GeomFromText(ntsGeometry.Intersection(_southSafeWorldPolygon).ToString());

            }

 

 

where _southSafeWorldPolyton and _northenWorldBound is:

        private static GisSharpBlog.NetTopologySuite.Geometries.Geometry _northerWorldBound = null;
        private static GisSharpBlog.NetTopologySuite.Geometries.Geometry _southestWorldBound = null;

        private static GisSharpBlog.NetTopologySuite.Geometries.Geometry _northSafeWorldPolygon = null;
        private static GisSharpBlog.NetTopologySuite.Geometries.Geometry _southSafeWorldPolygon = null;

        //create an nts GeometryFactory
        private static GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory _geometryFactory = null;

 

 

......  and inside in my function...

 

 

SharpMap.Geometries.Polygon safeWorld = new Polygon();
                safeWorld.ExteriorRing = new LinearRing();
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, 90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, -86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, -86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, 90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, 90));
                _northSafeWorldPolygon = GeometryConverter.ToNTSGeometry(safeWorld, _geometryFactory);

 

  	    if ( _geometryFactory == null )
            {
                _geometryFactory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory();
            }

            if (_northSafeWorldPolygon == null)
            {
                SharpMap.Geometries.Polygon safeWorld = new Polygon();
                safeWorld.ExteriorRing = new LinearRing();
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, 90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, -86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, -86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, 90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, 90));

                _northSafeWorldPolygon = GeometryConverter.ToNTSGeometry(safeWorld, _geometryFactory);
            }

            if (_southSafeWorldPolygon == null)
            {
                SharpMap.Geometries.Polygon safeWorld = new Polygon();
                safeWorld.ExteriorRing = new LinearRing();
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, -90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, 86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, 86.5));
                safeWorld.ExteriorRing.Vertices.Add(new Point(180, -90));
                safeWorld.ExteriorRing.Vertices.Add(new Point(-180, -90));

                _southSafeWorldPolygon = GeometryConverter.ToNTSGeometry(safeWorld, _geometryFactory);
            }

            if (_northerWorldBound == null)
            {
                SharpMap.Geometries.LineString ring = new LineString();
                ring.Vertices.Add(new Point(-180, 86.5));
                ring.Vertices.Add(new Point(180, 86.5));

                _northerWorldBound = GeometryConverter.ToNTSGeometry(ring, _geometryFactory);
            }

            if (_southestWorldBound == null)
            {
                SharpMap.Geometries.LineString ring = new LineString();
                ring.Vertices.Add(new Point(-180, -86.5));
                ring.Vertices.Add(new Point(180, -86.5));

                _southestWorldBound = GeometryConverter.ToNTSGeometry(ring, _geometryFactory);
            } 


 

 

 

This...    ok runs..... more or less...   but i don't like!...   i would run over ALL THE POINTS of the polygon and change the coordinate of the single point....     

 

how can i browse the vertices of a Geometry?

Coordinator
Mar 30, 2010 at 9:10 AM

Hello sandex,

Polygons have an ExteriorRing and an InteriorRings property.

ExteriorRing is defined as LinearRing, which is a closed LineString which has a Vertices property. Vertices is IList<Point>, so you can use foreach on those.

InteriorRings is defined as an IList<LinearRing> so you can use foreach on this list, too.

For NetTopologySuite Geometries there are similar properties. If you have further questions regarding the usage of NetTopologySuite please visit http://groups.google.com/group/nettopologysuite

 

Hth FObermaier

Mar 30, 2010 at 9:35 AM

FObermaier thankyou very much!...     as always in this last days :-)  eh eh   @ the end as first instance i've cut my polygon using the Net Topology functionalities and your nice GeometryConverter !  

Nov 11, 2011 at 3:27 AM

Hello FObermaier ,

      I just turn to sharpmap 2.0,I also use the functions of NTS then show result via mapviewcontrol,but I don't now how to use ?please help!!

 

 

Coordinator
Nov 11, 2011 at 9:25 AM

This is a broad question, can you be more specific?

cheers FObermaier