Пример #1
0
        /// <summary>
        /// Creates a buffer polygon that is Distance around mwShape
        /// </summary>
        /// <param name="mwShape">The polygon to buffer</param>
        /// <param name="Distance">The distance</param>
        /// <param name="QuadrantSegmants">how rounded the buffer is</param>
        /// <param name="EndCap">The type of endcap</param>
        /// <returns></returns>
        public static MapWinGIS.Shape Buffer(MapWinGIS.Shape mwShape, double Distance, int QuadrantSegmants, MapWindow.Interfaces.Geometries.BufferStyles EndCap)
        {
            IGeometry Buffer;
            Geometry  geom = NTS_Adapter.ShapeToGeometry(mwShape);

            Buffer = geom.Buffer(Distance, QuadrantSegmants, EndCap);
            return(NTS_Adapter.GeometryToShape(Buffer));
        }
Пример #2
0
        /// <summary>
        /// This is used by the Identity process to export all shapes intesecting all polygons passed in.
        /// Each identity polygon is used to select and clip input shapes. The new clipped shape is written
        /// to the result shapefile. The attribute fields from both input and identity shapefiles are copied
        /// to the result shapefile.
        /// This process uses a QuadTree index to speed up the selection of overlapping geometries.
        /// </summary>
        /// <param name="inputSF">The shapefile, of any geometry type, to be clipped and exported.</param>
        /// <param name="identitySF">The polygon shapefile used to clip the inputSF.</param>
        /// <param name="resultSF">The result shapefile that will contain the results.</param>
        /// <returns>False if an error occurs, true otherwise.</returns>
        public static bool ExportShapesWithPolygons(ref MapWinGIS.Shapefile inputSF, ref MapWinGIS.Shapefile identitySF, ref MapWinGIS.Shapefile resultSF)
        {
            try
            {
                // Boundary intersection test variables
                double xMin1, xMax1, yMin1, yMax1, zMin1, zMax1, xMin2, xMax2, yMin2, yMax2, zMin2, zMax2;

                // Build Quadtree index for inputSF
                MapWinGeoProc.NTS.Topology.Index.Quadtree.Quadtree myQuadTree = new MapWinGeoProc.NTS.Topology.Index.Quadtree.Quadtree();

                MapWinGIS.Shape currGeom;
                for (int i = 0; i < inputSF.NumShapes; i++)
                {
                    currGeom = inputSF.get_Shape(i);
                    currGeom.Extents.GetBounds(out xMin1, out yMin1, out zMin1, out xMax1, out yMax1, out zMax1);
                    Envelope myItemEnv = new Envelope(xMin1, xMax1, yMin1, yMax1);
                    myQuadTree.Insert(myItemEnv, i);
                }//end of looping through lines

                // Copy inputSf and identitySF fields to resultSF, renaming duplicate fields
                if (Globals.CopyFields(ref inputSF, ref resultSF) == false)
                {
                    return(false);
                }
                if (Globals.CopyFields(ref identitySF, ref resultSF, true) == false)
                {
                    return(false);
                }

                int             resultNumFields             = resultSF.NumFields;
                int             inputNumFields              = inputSF.NumFields;
                int             identityNumFields           = identitySF.NumFields;
                int             shpIndex                    = 0;
                Envelope        myQueryEnv                  = null;
                Geometry        queryPoly                   = null;
                Geometry        inputGeom                   = null;
                IGeometry       intersectGeom               = null;
                MapWinGIS.Shape identityShape               = null;
                MapWinGIS.Shape intersectShape              = null;
                IList           results                     = null;
                string          progressmessage             = "";
                int             inputShapesForIdentityShape = 0;

                // Loop through identitySF and get inputSF geometries that intersect
                for (int identityIndex = 0; identityIndex < identitySF.NumShapes; identityIndex++)
                {
                    identityShape = identitySF.get_Shape(identityIndex);
                    queryPoly     = NTS_Adapter.ShapeToGeometry(identityShape);
                    identityShape.Extents.GetBounds(out xMin2, out yMin2, out zMin2, out xMax2, out yMax2, out zMax2);
                    myQueryEnv = new Envelope(xMin2, xMax2, yMin2, yMax2);

                    //use quadtree index to find geometries that may intersect
                    results = myQuadTree.Query(myQueryEnv);
                    int intersectIndex = 0;
                    for (int i = 0; i < results.Count; i++)
                    {
                        intersectIndex = Convert.ToInt32(results[i]);                                                                                                                                                                          // Get input id from quadtree results
                        currGeom       = inputSF.get_Shape(intersectIndex);                                                                                                                                                                    // Get input geometry
                        inputGeom      = NTS_Adapter.ShapeToGeometry(currGeom);                                                                                                                                                                // Convert to NTS Geometry
                        for (int inputGoemIndex = 0; inputGoemIndex < inputGeom.NumGeometries; inputGoemIndex++)                                                                                                                               //use each part of the geometry
                        {
                            if (inputGeom.GetGeometryN(inputGoemIndex).Intersects(queryPoly))                                                                                                                                                  // check for intersection
                            {
                                intersectGeom = MapWinGeoProc.NTS.Topology.Operation.Overlay.OverlayOp.Overlay(queryPoly, inputGeom.GetGeometryN(inputGoemIndex), MapWinGeoProc.NTS.Topology.Operation.Overlay.SpatialFunctions.Intersection); // create intersect geometry
                                if (!intersectGeom.IsEmpty)
                                {
                                    for (int geomIndex = 0; geomIndex < intersectGeom.NumGeometries; geomIndex++)                                          // process each part of intersect result
                                    {
                                        if (inputGeom.GetGeometryN(inputGoemIndex).GetType().Name == intersectGeom.GetGeometryN(geomIndex).GetType().Name) // only used geometries of the same type as the input.
                                        {
                                            // Write shape geometry
                                            intersectShape = NTS_Adapter.GeometryToShape(intersectGeom.GetGeometryN(geomIndex));
                                            shpIndex       = resultSF.NumShapes;
                                            if (resultSF.EditInsertShape(intersectShape, ref shpIndex) == false)
                                            {
                                                gErrorMsg = string.Format("Problem inserting shape into result file: {0}, Input Id: {1}, IdentityId: {2}", resultSF.get_ErrorMsg(resultSF.LastErrorCode), intersectIndex, identityIndex);
                                                Debug.WriteLine(gErrorMsg);
                                                Error.SetErrorMsg(gErrorMsg);
                                                return(false);
                                            }
                                            inputShapesForIdentityShape++;
                                            intersectShape = null;
                                            //add the table values from input SF
                                            for (int j = 0; j <= inputNumFields - 1; j++)
                                            {
                                                if (resultSF.EditCellValue(j, shpIndex, inputSF.get_CellValue(j, intersectIndex)) == false)
                                                {
                                                    gErrorMsg = "Problem inserting value into DBF table: " + resultSF.get_ErrorMsg(resultSF.LastErrorCode);
                                                    Debug.WriteLine(gErrorMsg);
                                                    Error.SetErrorMsg(gErrorMsg);
                                                    return(false);
                                                }
                                            }//end of looping through table
                                            //add the table values from identity SF
                                            for (int j = 0; j <= identityNumFields - 1; j++)
                                            {
                                                if (resultSF.EditCellValue(j + inputNumFields, shpIndex, identitySF.get_CellValue(j, identityIndex)) == false)
                                                {
                                                    gErrorMsg = "Problem inserting value into DBF table: " + resultSF.get_ErrorMsg(resultSF.LastErrorCode);
                                                    Debug.WriteLine(gErrorMsg);
                                                    Error.SetErrorMsg(gErrorMsg);
                                                    return(false);
                                                }
                                            }//end of looping through table
                                        }
                                    }
                                }
                            }
                        }
                        inputGeom = null;
                    }
                    progressmessage = string.Format("{3}: Identity Index:{0}, Quadtree Results:{1}, Shapes added:{2}", identityIndex, results.Count, inputShapesForIdentityShape, DateTime.Now.ToShortTimeString());
                    results.Clear();
                    Debug.WriteLine(progressmessage);
                    inputShapesForIdentityShape = 0;
                    resultSF.StopEditingShapes(true, true, null);
                    resultSF.StartEditingShapes(true, null);
                }
                return(resultSF.NumShapes > 0);
            }
            catch (Exception E)
            {
                System.Windows.Forms.MessageBox.Show(E.ToString());
                return(false);
            }
        }