/// <summary>
        /// This method takes a pre-populated FeatureDataTable and removes rows that do not truly intersect testGeometry
        /// </summary>
        /// <param name="featureDataTable">The FeatureDataTable instance to filter</param>
        /// <param name="testGeometry">the geometry to compare against</param>
        public void PostFilterExistingFeatureDataTable(FeatureDataTable featureDataTable, SMGeometry testGeometry)
        {
            //first we create a new GeometryFactory.
            var geometryFactory = new GeometryFactory();


            //then we convert the testGeometry into the equivalent NTS geometry
            GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory);


            //now we loop backwards through the FeatureDataTable
            for (int i = featureDataTable.Rows.Count - 1; i > -1; i--)
            {
                //we get each row
                FeatureDataRow featureDataRow = featureDataTable.Rows[i] as FeatureDataRow;
                //and get the rows' geometry
                SMGeometry compareGeometry = featureDataRow.Geometry;
                //convert the rows' geometry into the equivalent NTS geometry
                GeoAPI.Geometries.IGeometry compareGeometryAsNts = GeometryConverter.ToNTSGeometry(compareGeometry, geometryFactory);
                //now test for intesection (note other operations such as Contains, Within, Disjoint etc can all be done the same way)
                bool intersects = testGeometryAsNtsGeom.Intersects(compareGeometryAsNts);

                //if it doesn't intersect remove the row.
                if (!intersects)
                {
                    featureDataTable.Rows.RemoveAt(i);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/>
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(IProvider provider)
        {
            // Features list initialization
            _features = new List <Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                Collection <uint> ids = provider.GetObjectIDsInView(provider.GetExtents());
                foreach (uint id in ids)
                {
                    FeatureDataRow dataRow = provider.GetFeature(id);
                    GeoAPI.Geometries.IGeometry geometry   = GeometryConverter.ToNTSGeometry(dataRow.Geometry, _geometryFactory);
                    AttributesTable             attributes = new AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {
                        if (dataRow[column] == null || dataRow[column] is DBNull)
                        {
                            throw new ApplicationException("Null values not supported");
                        }
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    _features.Add(new Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                {
                    provider.Close();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds"></param>
        public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds)
        {
            GeoAPI.Geometries.IGeometry geometry  = GeometryConverter.ToNTSGeometry(geom, _geometryFactory);
            FeatureDataTable            dataTable = CreateFeatureDataTable();

            foreach (Feature feature in _features)
            {
                if (feature.Geometry.Intersects(geometry))
                {
                    CreateNewRow(dataTable, feature);
                }
            }

            ds.Tables.Add(dataTable);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="ds"></param>
        public void ExecuteIntersectionQuery(SharpMap.Geometries.Geometry geom, FeatureDataSet ds)
        {
            GisSharpBlog.NetTopologySuite.Geometries.Geometry geometry = GeometryConverter.ToNTSGeometry(geom, geometryFactory);
            SharpMap.Data.FeatureDataTable dataTable = CreateFeatureDataTable();

            foreach (GisSharpBlog.NetTopologySuite.Features.Feature feature in features)
            {
                if (feature.Geometry.Intersects(geometry))
                {
                    CreateNewRow(dataTable, feature);
                }
            }

            ds.Tables.Add(dataTable);
        }
        /// <summary>
        /// This method returns a FeatureDataTable containing all the rows from the shapefile that intersect the testGeometry.
        /// The ShapeFile.ExecuteIntersectionQuery method only tests bounding boxes so we use the FilterDelegate property to add a true
        /// intersection test using NetTopologySuite
        /// </summary>
        /// <param name="pathToShapefile">The path to the shapefile</param>
        /// <param name="testGeometry">The geometry that we want to test against</param>
        /// <returns></returns>
        public FeatureDataTable GetIntersectingFeaturesUsingFilterDelegate(string pathToShapefile, SMGeometry testGeometry)
        {
            //create a new shapefile provider
            using (ShapeFile shapefile = new ShapeFile(pathToShapefile))
            {
                //create an nts GeometryFactory
                GeometryFactory geometryFactory = new GeometryFactory();

                //convert the testGeometry into the equivalent NTS geometry
                GeoAPI.Geometries.IGeometry testGeometryAsNtsGeom = GeometryConverter.ToNTSGeometry(testGeometry, geometryFactory);

                SMGeometry check = GeometryConverter.ToSharpMapGeometry(testGeometryAsNtsGeom);
                if (!check.Equals(testGeometry))
                {
                    throw new ApplicationException("conversion error");
                }

                //set the shapefile providers' FilterDelegate property to a new anonymous method
                //this delegate method will be called for each potential row
                shapefile.FilterDelegate = delegate(FeatureDataRow featureDataRow)
                {
                    //get the geometry from the featureDataRow
                    SMGeometry rowGeometry = featureDataRow.Geometry;
                    //convert it to the equivalent NTS geometry
                    GeoAPI.Geometries.IGeometry compareGeometryAsNtsGeometry =
                        GeometryConverter.ToNTSGeometry(rowGeometry, geometryFactory);
                    //do the test. Note that the testGeometryAsNtsGeometry is available here because it is
                    //declared in the same scope as the anonymous method.
                    bool intersects =
                        testGeometryAsNtsGeom.Intersects(compareGeometryAsNtsGeometry);
                    //return the result
                    return(intersects);
                };


                //create a new FeatureDataSet
                FeatureDataSet featureDataSet = new FeatureDataSet();
                //open the shapefile
                shapefile.Open();
                //call ExecuteIntersectionQuery. The FilterDelegate will be used to limit the result set
                shapefile.ExecuteIntersectionQuery(testGeometry, featureDataSet);
                //close the shapefile
                shapefile.Close();
                //return the populated FeatureDataTable
                return(featureDataSet.Tables[0]);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Builds from the given provider.
        /// </summary>
        /// <param name="provider">
        /// The base <see cref="SharpMap.Data.Providers.IProvider"/>
        /// from witch initialize the <see cref="NtsProvider"/> instance.
        /// </param>
        private void BuildFromProvider(SharpMap.Data.Providers.IProvider provider)
        {
            // Features list initialization
            features = new List <GisSharpBlog.NetTopologySuite.Features.Feature>(provider.GetFeatureCount());

            try
            {
                // Load all features from the given provider
                provider.Open();
                Collection <uint> ids = provider.GetObjectIDsInView(provider.GetExtents());
                foreach (uint id in ids)
                {
                    SharpMap.Data.FeatureDataRow dataRow = provider.GetFeature(id);
                    GisSharpBlog.NetTopologySuite.Geometries.Geometry      geometry   = GeometryConverter.ToNTSGeometry(dataRow.Geometry, geometryFactory);
                    GisSharpBlog.NetTopologySuite.Features.AttributesTable attributes = new GisSharpBlog.NetTopologySuite.Features.AttributesTable();
                    foreach (DataColumn column in dataRow.Table.Columns)
                    {
                        if (dataRow[column] == null || dataRow[column].GetType() == typeof(System.DBNull))
                        {
                            throw new ApplicationException("Null values not supported");
                        }
                        attributes.AddAttribute(column.ColumnName, dataRow[column]);
                    }
                    features.Add(new GisSharpBlog.NetTopologySuite.Features.Feature(geometry, attributes));
                }
            }
            finally
            {
                if (provider.IsOpen)
                {
                    provider.Close();
                }
            }
        }
Beispiel #7
0
        // FragmentFilter overrides
        public override FragmentList process(FeatureList input, FilterEnv env)
        {
            FragmentList output = new FragmentList();

            //cuidado con las entidades dentro del for

            int     i = 0;
            Vector3 scale;
            Vector3 distanceScale;
            Vector3 mScale = new Vector3(1, 1, 1);
            float   lWidth = 1;

            if (Scale != null)
            {
                scale = Registry.instance().GetEngine("Python").run(Scale).asVec3();
            }
            else
            {
                scale = new Vector3(1, 1, 1);
            }

            if (CoordScale != null)
            {
                distanceScale = Registry.instance().GetEngine("Python").run(CoordScale).asVec3();
            }
            else
            {
                distanceScale = new Vector3(1, 1, 1);
            }
            if (LineWidth != null)
            {
                lWidth = Registry.instance().GetEngine("Python").run(LineWidth).asFloat();
            }
            if (MaterialScale != null)
            {
                mScale = Registry.instance().GetEngine("Python").run(MaterialScale).asVec3();
            }

            SceneNode nodeIni = point3d(env.getName(), i, 0, 0, 0, null, env.getSceneMgr());

#if ESCALA_NODO_INICIAL
            if (Scale != null)
            {
                nodeIni.SetScale(Registry.instance().GetEngine("Python").run(Scale).asVec3());
            }
            if (coordScale != null)
            {
                Vector3 vec3 = Registry.instance().GetEngine("Python").run(Scale).asVec3();
                nodeIni.SetPosition(nodeIni.Position.x * vec3.x, nodeIni.Position.y * vec3.y, nodeIni.Position.z * vec3.z);
#if TRACE_BUILDGEOMFILTER
                System.Console.WriteLine("(" + n.Position.x + "," + n.Position.y + ")");
#endif
            }
#endif
            Fragment fIni = new Fragment(nodeIni);
            output.Add(fIni);

            foreach (Feature feature in input)
            {
                //if type of features is Point
                if (feature.row.Geometry is SharpMap.Geometries.Point)
                {
                    SharpMap.Geometries.Point p = (SharpMap.Geometries.Point)feature.row.Geometry;

                    i++;
                    SceneNode n = point3d(env.getName(), i, (float)p.X, (float)p.Y, 0, nodeIni, env.getSceneMgr());

                    n.SetScale(scale);
                    n.SetPosition(n.Position.x * distanceScale.x, n.Position.y * distanceScale.y, n.Position.z * distanceScale.z);

                    Fragment f = new Fragment(n);
                    output.Add(f);
                }

                //if type of features is Polygon
                else if (feature.row.Geometry is SharpMap.Geometries.Polygon)
                {
                    SharpMap.Geometries.Polygon polygon = (SharpMap.Geometries.Polygon)feature.row.Geometry;

                    ManualObject polygonNode = null;

                    if (polygonNode == null)
                    {
                        polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                        MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        material.GetTechnique(0).GetPass(0).VertexColourTracking =
                            (int)TrackVertexColourEnum.TVC_AMBIENT;

                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();

                        int        numVertices = polygon.ExteriorRing.NumPoints /*/10+1*/;
                        int        numValores  = 3;
                        double[][] data        = new double[numVertices][];

                        for (int j = 0; j < numVertices; j++)
                        {
                            data[j] = new double[numValores];
                        }

                        int k = 0;
                        //1 polygon = N vertices
                        foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                        {
                            //if (k % 10 == 0)
                            {
                                data[k /*/10*/][0] = point.X;
                                data[k /*/10*/][1] = point.Y;
                                data[k /*/10*/][2] = 0;
                            }
                            k++;

                            //SceneNode n = point3d(env.getName()+i+k, k + 10, (float)point.X * 10.0f, (float)point.Y * 10.0f, 0, nodeIni, env.getSceneMgr());
                        }
                        for (int j = 0; j < data.GetLength(0); j++)
                        {
                            Glu.gluTessVertex(data[j], 0, new Vector3((float)(data[j][1] * distanceScale.y), (float)(data[j][2] * distanceScale.z), (float)(data[j][0] * distanceScale.x)));
                        }

                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();

                        nodeIni.AttachObject(polygonNode);
                    }
                    i++;
                }

                //if type of features is MultiPolygon
                else if (feature.row.Geometry is SharpMap.Geometries.MultiPolygon)
                {
                    SharpMap.Geometries.MultiPolygon mp = (SharpMap.Geometries.MultiPolygon)feature.row.Geometry;

                    // 1 MultiPolygon = N polygon
                    foreach (SharpMap.Geometries.Polygon polygon in mp.Polygons)
                    {
                        ManualObject polygonNode = null;

                        if (polygonNode == null)
                        {
                            polygonNode = env.getSceneMgr().CreateManualObject(env.getName() + "Node_" + i);
                            MaterialPtr material = MaterialManager.Singleton.Create("Test/ColourPolygon",
                                                                                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                            material.GetTechnique(0).GetPass(0).VertexColourTracking =
                                (int)TrackVertexColourEnum.TVC_AMBIENT;


                            //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                            MogreTessellationCallbacks callback = new MogreTessellationCallbacks(polygonNode, Color, feature);

                            if (nameMaterial != null)
                            {
                                callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                                callback.MaterialScale = mScale;
                            }

                            GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                            Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                            Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                            Glu.gluTessBeginPolygon(null);
                            Glu.gluTessBeginContour();

                            int        numVertices = polygon.ExteriorRing.NumPoints;
                            int        numValores  = 3;
                            double[][] data        = new double[numVertices][];

                            for (int j = 0; j < numVertices; j++)
                            {
                                data[j] = new double[numValores];
                            }

                            int k = 0;
                            //1 polygon = N vertices
                            foreach (SharpMap.Geometries.Point point in polygon.ExteriorRing.Vertices)
                            {
                                data[k][0] = point.X;
                                data[k][1] = point.Y;
                                data[k][2] = 0;

                                k++;

                                //SceneNode n = point3d(env.getName(), i, (float)point.X, (float)point.Y, 0, nodeIni, env.getSceneMgr());
                            }
                            for (int j = 0; j < data.GetLength(0); j++)
                            {
                                Glu.gluTessVertex(data[j], 0, new Vector3(((float)data[j][1]) * distanceScale.y, ((float)data[j][2]) * distanceScale.z, ((float)data[j][0]) * distanceScale.x));
                            }

                            Glu.gluTessEndContour();
                            Glu.gluTessNormal(0, 0, 1);
                            Glu.gluTessEndPolygon();

                            nodeIni.AttachObject(polygonNode);
                        }
                        i++;
                    }
                }

                //if type of features is Line
                else if (feature.row.Geometry is SharpMap.Geometries.ILineal /*SharpMap.Geometries.LineString*/)
                {
                    System.Collections.Generic.List <SharpMap.Geometries.ILineal> lineas = new System.Collections.Generic.List <SharpMap.Geometries.ILineal>();
                    if (feature.row.Geometry is SharpMap.Geometries.MultiLineString)
                    {
                        foreach (SharpMap.Geometries.LineString l in ((SharpMap.Geometries.MultiLineString)(feature.row.Geometry)).LineStrings)
                        {
                            lineas.Add(l);
                        }
                    }
                    else
                    {
                        lineas.Add((SharpMap.Geometries.ILineal)(feature.row.Geometry));
                    }
                    foreach (SharpMap.Geometries.ILineal line in lineas)
                    {
                        ManualObject lineNode = env.getSceneMgr().CreateManualObject("line" + i);

                        //MaterialPtr material = MaterialManager.Singleton.Create(nameMaterial,
                        //ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        //material.GetTechnique(0).GetPass(0).VertexColourTracking =
                        //               (int)TrackVertexColourEnum.TVC_AMBIENT;
                        //material.GetTechnique(0).GetPass(0).SetDepthBias(100);
                        //material.GetTechnique(0).GetPass(0).LightingEnabled = false;

                        int nSeg = 5; // Number of segments on the cap or join pieces
                        BufferParameters         param           = new BufferParameters(nSeg, BufferParameters.BufferEndCapStyle.CapRound, BufferParameters.BufferJoinStyle.JoinRound, 2);
                        IGeometryFactory <Coord> geometryFactory = new GeometryFactory <Coord>(new CoordSeqFac(new CoordFac(PrecisionModelType.DoubleFloating)));
                        //IWktGeometryReader<Coord> reader = geometryFactory.WktReader;
                        //string txt = feature.row.Geometry.AsText();
                        ILineString         line1       = (ILineString)GeometryConverter.ToNTSGeometry((SharpMap.Geometries.LineString)line, geometryFactory); // (ILineString<Coord>)reader.Read(txt);
                        IGeometry           coordBuffer = line1.Buffer(lWidth, param);
                        ICoordinateSequence coords      = coordBuffer.Coordinates;
                        //Vector3 v = Registry.instance().GetEngine("Python").run(Color, feature, null).asVec3();
                        MogreTessellationCallbacks callback = new MogreTessellationCallbacks(lineNode, Color, feature);
                        if (nameMaterial != null)
                        {
                            callback.Material      = nameMaterial; // "Test/ColourPolygon2";
                            callback.MaterialScale = mScale;
                        }

                        GLUtessellatorImpl Glu = (GLUtessellatorImpl)GLUtessellatorImpl.gluNewTess();
                        Glu.gluTessCallback(GLU.GLU_TESS_VERTEX, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_BEGIN, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_END, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_ERROR, callback);
                        Glu.gluTessCallback(GLU.GLU_TESS_COMBINE, callback);
                        Glu.gluTessBeginPolygon(null);
                        Glu.gluTessBeginContour();
                        foreach (Coord coord in coords)
                        {
                            double[] data = new double[] { coord.X *distanceScale.x, coord.Y *distanceScale.y, (double.IsNaN(coord.Z) ? 0 : coord.Z) * distanceScale.z };

                            Glu.gluTessVertex(data, 0, new Vector3((float)data[1], (float)data[2], (float)data[0]));
                        }
                        Glu.gluTessEndContour();
                        Glu.gluTessNormal(0, 0, 1);
                        Glu.gluTessEndPolygon();
                        i++;
                        nodeIni.AttachObject(lineNode);
                    }
                    if ((feature.row.Geometry is SharpMap.Geometries.Polygon) | (feature.row.Geometry is SharpMap.Geometries.MultiPolygon))
                    {
                        Fragment f = new Fragment(nodeIni);
                        output.Add(f);
                    }
                }
            }
            i = 0;//breakpoint

            /*foreach (Fragment fragment in output)
             * {
             *  fragment.Node.Scale(0,0,0);
             * }*/

#if TODO
            // if features are arriving in batch, resolve the color here.
            // otherwise we will resolve it later in process(feature,env).
            is_batch            = input.Count > 1;
            batch_feature_color = overall_color;
            if (is_batch && getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), env);
                if (r.isValid())
                {
                    batch_feature_color = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(base.process(input, env));
#endif
            //throw new NotImplementedException();

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList   l      = filter.process(input, env);
                    //FeatureList l = successor.process(input, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList   l      = filter.process(output, env);
                }
            }

            return(output);
        }
Beispiel #8
0
        public static FeatureDataRow LocatePolygon2(SharpMap.Geometries.Point punto, SharpMap.Data.FeatureDataTable fdt)
        {
            FeatureDataRow fdr = null;

            if ((fdt as DataTable).Rows.Count == 1)
            {
                fdr = (FeatureDataRow)(fdt as DataTable).Rows[0];
            }
            else
            {
                GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory f = new GeometryFactory(new PrecisionModel());
                foreach (DataRow r in (fdt as DataTable).Rows)
                {
                    if ((r as  FeatureDataRow).Geometry.GetType() == typeof(SharpMap.Geometries.MultiPolygon))
                    {
                        // Doble cast: de Geometria a MultiPolygon, y de DataRow a FeatureDataRow.
                        SharpMap.Geometries.MultiPolygon SharpMultiPol = (SharpMap.Geometries.MultiPolygon)(r as  FeatureDataRow).Geometry;
                        GisSharpBlog.NetTopologySuite.Geometries.Geometry[] NTSGeom = GeometryConverter.ToNTSGeometry(new SharpMap.Geometries.Geometry[1] {
                            SharpMultiPol
                        }, f);
                        GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon NTSMultiPol = (GisSharpBlog.NetTopologySuite.Geometries.MultiPolygon)NTSGeom[0];
                        if (NTSMultiPol.Contains(new GisSharpBlog.NetTopologySuite.Geometries.Point(punto.X, punto.Y)) == true)
                        {
                            fdr = (FeatureDataRow)r;
                            break;
                        }
                    }
                }
            }
            return(fdr);
        }