Can't use NTS to perform true contains

Topics: SharpMap v0.9 / v1.x
Nov 26, 2012 at 10:15 AM

Hi,

I'm having issues with the trying to convert a Geometry to NTS.

As shown in the code below, I'm trying to convert a geometry from SharpMap to Nts. However I get the error:

Method not found: 'GeoAPI.Geometries.ILinearRing GeoAPI.Geometries.IGeometryFactory.CreateLinearRing(GeoAPI.Geometries.ICoordinate[])'.

Am I converting this correctly? Also, I keep seeing xxx.ExecuteIntersectionQuery(...) in the discussions. Which is the better approach? What is the difference between converting the geometry to NTS vs using a NtsProvider?

And for the record, I couldn't get the NtsProvider to work too.

 

 

 

using System;
using System.Collections.Generic;
using SharpMap.Data;
using SharpMap.Data.Providers;
using SharpMap.Geometries;
using SharpMap.Converters.NTS;

namespace Spatial
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var conn = new Oracle("...", "...", "...", "...", "...", "..."))
            {
                conn.Open();
                var geoms = new Dictionary<uint, Geometry>();

                var geom = conn.GetGeometryByID(1);
                var bbox = geom.GetBoundingBox();

                var inside = 0;

                var pts = new List<Point>();
                for (var vertical = bbox.Top; vertical >= bbox.Bottom; vertical -= 0.001)
                {
                    for (var horizontal = bbox.Left; horizontal <= bbox.Right; horizontal += 0.001)
                    {
                        pts.Add(new Point(horizontal, vertical));
                    }
                }

                var startdt = DateTime.Now;

                var geomFactory = new NetTopologySuite.Geometries.GeometryFactory();

// Error occurs here: Method not found: 'GeoAPI.Geometries.ILinearRing GeoAPI.Geometries.IGeometryFactory.CreateLinearRing(GeoAPI.Geometries.ICoordinate[])'.
                var n = GeometryConverter.ToNTSGeometry(geom, geomFactory);

                pts.AsParallel().ForAll(pt =>
                {
                    if (SpatialRelationsEx.Contains(geom, pt))
                        Interlocked.Increment(ref inside);
                });

                var enddt = DateTime.Now;
                Console.WriteLine("{0}/{1}, time taken: {2}", inside, pts.Count, enddt - startdt);
            }
        }
    }
}

 

Coordinator
Nov 27, 2012 at 7:57 AM

If you are using the latest build or compile the source yourself you should not be needing to use SpatialRelationsEx, since GeoAPI/NTS Geometries are used within SharpMap directly.

The usage of ICoordinate implies that you are referencing some old code.

Hth FObermaier

Nov 27, 2012 at 11:55 AM

Ah... then where can I get the latest build? Because I've downloaded the binaries from the site. Isn't that the latest build?

Also, can someone tell me how to compile from the source code because I have problems doing so.

Developer
Nov 27, 2012 at 1:00 PM
tokens wrote:

Ah... then where can I get the latest build? Because I've downloaded the binaries from the site. Isn't that the latest build?

Also, can someone tell me how to compile from the source code because I have problems doing so.

You can find a "download" botton in this page: http://sharpmap.codeplex.com/SourceControl/changeset/view/100480 

Yhen open sharpmap solution from the trunk and all should be fine.