Exemplo n.º 1
0
        private static Geometry Intersect(IFeature f, IGeometry envelope)
        {
            Geometry clip;

            if (f.GeometryType == "GeometryCollection")
            {
                // This hack because DotSpatial 1.9 throws NullReferenceException when trying to Intersect GeometryCollection
                List <IBasicGeometry> arr = new List <IBasicGeometry>();
                for (int i = 0; i < f.NumGeometries; i++)
                {
                    IBasicGeometry g            = f.GetBasicGeometryN(i);
                    IFeature       intersection = new Feature(g).Intersection(envelope);
                    if (intersection == null)
                    {
                        continue;
                    }
                    clip = (Geometry)intersection.BasicGeometry;
                    arr.Add(clip);
                }
                clip = new GeometryCollection(arr, new GeometryFactory());
            }
            else
            {
                IFeature intersection = f.Intersection(envelope);
                if (intersection == null)
                {
                    return(null);
                }
                clip = (Geometry)intersection.BasicGeometry;
            }
            return(clip);
        }
Exemplo n.º 2
0
        // metric coordinates
        public static IFeatureSet CreateUserInputLayer(double lon, double lat, double radius, string workdir)
        {
            FeatureSet infs = new FeatureSet(DotSpatial.Topology.FeatureType.Point);

            infs.Projection = KnownCoordinateSystems.Projected.WorldSpheroid.Mercatorsphere;
            DotSpatial.Data.Feature center = new DotSpatial.Data.Feature(new Coordinate(lon, lat));
            infs.AddFeature(center);

            var fs = infs.Buffer(radius, false);

            fs.SaveAs(WORKSPACE_DIR + workdir + "/usr.shp", true);
            return(fs);
        }