Exemple #1
0
        public static List <IShape> Project(List <IShape> values, CoordinateReferenceSystemBase sourceSrs, CoordinateReferenceSystemBase targetSrs)
        {
            List <IShape> result = new List <IShape>(values.Count);

            if (sourceSrs.Ellipsoid.AreTheSame(targetSrs.Ellipsoid))
            {
                for (int i = 0; i < values.Count; i++)
                {
                    var c1 = values[i].Transform(p => sourceSrs.ToGeodetic(p));

                    result.Add(c1.Transform(p => targetSrs.FromGeodetic(p)));
                }
            }
            else
            {
                for (int i = 0; i < values.Count; i++)
                {
                    var c1 = values[i].Transform(p => sourceSrs.ToGeodetic(p));

                    result.Add(c1.Transform(p => targetSrs.FromGeodetic(p, sourceSrs.Ellipsoid)));
                }
            }

            return(result);
        }
        public static List <Geometry> Project(this List <Geometry> values, CoordinateReferenceSystemBase sourceSrs, CoordinateReferenceSystemBase targetSrs)
        {
            List <Geometry> result = new List <Geometry>(values.Count);

            if (sourceSrs.Ellipsoid.AreTheSame(targetSrs.Ellipsoid))
            {
                for (int i = 0; i < values.Count; i++)
                {
                    var c1 = values[i].Transform(p => sourceSrs.ToGeodetic(p), SridHelper.GeodeticWGS84);

                    result.Add(c1.Transform(p => targetSrs.FromGeodetic(p), targetSrs.Srid));
                }
            }
            else
            {
                for (int i = 0; i < values.Count; i++)
                {
                    var c1 = values[i].Transform(p => sourceSrs.ToGeodetic(p), SridHelper.GeodeticWGS84);

                    result.Add(c1.Transform(p => targetSrs.FromGeodetic(p, sourceSrs.Ellipsoid), targetSrs.Srid));
                }
            }

            return(result);
        }
        public static PrjFile AsEsriPrj(this CoordinateReferenceSystemBase mapProjection)
        {
            switch (mapProjection.Type)
            {
            case MapProjectionType.None:
                return(new PrjFile(new PrjTree(mapProjection.Ellipsoid, mapProjection.Title)));

            case MapProjectionType.AlbersEqualAreaConic:
            case MapProjectionType.AzimuthalEquidistant:
                throw new NotImplementedException();

            case MapProjectionType.CylindricalEqualArea:
                return(AsEsriPrjFile((CylindricalEqualArea)mapProjection));

            case MapProjectionType.LambertConformalConic:
                return(AsEsriPrjFile((LambertConformalConic)mapProjection));

            case MapProjectionType.Mercator:
                return(AsEsriPrjFile((Mercator)mapProjection));

            case MapProjectionType.TransverseMercator:
                return(AsEsriPrjFile((TransverseMercator)mapProjection));

            case MapProjectionType.UTM:
                return(AsEsriPrjFile((UTM)mapProjection));

            case MapProjectionType.WebMercator:
                return(AsEsriPrjFile((WebMercator)mapProjection));

            default:
                throw new NotImplementedException();
            }
        }
        public static IPoint Project(this IPoint point, CoordinateReferenceSystemBase sourceSrs, CoordinateReferenceSystemBase targetSrs)
        {
            if (sourceSrs.Ellipsoid.AreTheSame(targetSrs.Ellipsoid))
            {
                var c1 = sourceSrs.ToGeodetic(point);

                return(targetSrs.FromGeodetic(c1));
            }
            else
            {
                var c1 = sourceSrs.ToGeodetic(point);

                return(targetSrs.FromGeodetic(c1, sourceSrs.Ellipsoid));
            }
        }
Exemple #5
0
        public static List <IShape> Project(string shpFileName, CoordinateReferenceSystemBase targetCrs)
        {
            var sourcePrj = GetPrjFileName(shpFileName);

            if (!System.IO.File.Exists(sourcePrj))
            {
                throw new System.IO.FileNotFoundException($"prj file not found. {sourcePrj}");
            }

            var sourceCrs = new Prj.PrjFile(sourcePrj).AsMapProjection();

            var data = Read(shpFileName).ToList();

            return(Project(data, sourceCrs, targetCrs));

            ////Old Method
            //var sourcePrj = GetPrjFileName(shpFileName);
            //if (!System.IO.File.Exists(sourcePrj))
            //{
            //    throw new System.IO.FileNotFoundException($"prj file not found. {sourcePrj}");
            //}
            //var sourceCrs = new Prj.PrjFile(sourcePrj).AsMapProjection();
            //var data = Read(shpFileName).ToList();
            //List<IShape> result = new List<IShape>(data.Count);
            //if (sourceCrs.Ellipsoid.AreTheSame(targetCrs.Ellipsoid))
            //{
            //    for (int i = 0; i < data.Count; i++)
            //    {
            //        var c1 = data[i].Transform(p => sourceCrs.ToGeodetic(p));
            //        result.Add(c1.Transform(p => targetCrs.FromGeodetic(p)));
            //    }
            //}
            //else
            //{
            //    for (int i = 0; i < data.Count; i++)
            //    {
            //        var c1 = data[i].Transform(p => sourceCrs.ToGeodetic(p));
            //        result.Add(c1.Transform(p => targetCrs.FromGeodetic(p, sourceCrs.Ellipsoid)));
            //    }
            //}
            //return result;
        }
Exemple #6
0
        public static void SaveAsShapefile(string shpFileName, IEnumerable <IShape> data, bool createEmptyDbf, CoordinateReferenceSystemBase coordinateReferenceSystem, bool overwrite = false)
        {
            Writer.ShpWriter.Write(shpFileName, data, createEmptyDbf, overwrite);

            var prj = GetPrjFileName(shpFileName);

            if (overwrite && System.IO.File.Exists(prj))
            {
                System.IO.File.Delete(prj);
            }

            coordinateReferenceSystem.AsEsriPrj().Save(prj);
        }
Exemple #7
0
        public static void ProjectAndSaveAsShapefile(string sourceShapefileName, string targetShapefileName, CoordinateReferenceSystemBase targetCrs, bool overwrite = false)
        {
            if (!CheckAllNeededFilesExists(sourceShapefileName, true))
            {
                throw new NotImplementedException();
            }

            var result = Project(sourceShapefileName, targetCrs);

            //result.ToList().Select(i=>i.MinimumBoundingBox).ToList()
            SaveAsShapefile(targetShapefileName, result, false, targetCrs, overwrite);

            var destinationDbfFileName = GetDbfFileName(targetShapefileName);

            System.IO.File.Copy(GetDbfFileName(sourceShapefileName), destinationDbfFileName, overwrite);
        }
Exemple #8
0
 public static Task <List <IShape> > ProjectAsync(string shpFileName, CoordinateReferenceSystemBase targetCrs)
 {
     return(Task.Run(() => Project(shpFileName, targetCrs)));
 }
Exemple #9
0
        public static Task <ShapefileDataSource <object> > Create(string shapeFileName, string spatialColumnName, int srid, Encoding encoding, CoordinateReferenceSystemBase targetCrs, string labelColumnName = null)
        {
            return(Task.Run <ShapefileDataSource <object> >(() =>
            {
                var sourcePrj = IRI.Ket.ShapefileFormat.Shapefile.GetPrjFileName(shapeFileName);

                if (!System.IO.File.Exists(sourcePrj))
                {
                    throw new System.IO.FileNotFoundException($"prj file not found. {sourcePrj}");
                }

                var sourceCrs = new ShapefileFormat.Prj.PrjFile(sourcePrj).AsMapProjection();

                Func <Point, Point> func = null;

                if (sourceCrs.Ellipsoid.AreTheSame(targetCrs.Ellipsoid))
                {
                    func = new Func <Point, Point>(p => (Point)targetCrs.FromGeodetic(sourceCrs.ToGeodetic(p)));
                }
                else
                {
                    func = new Func <Point, Point>(p => (Point)targetCrs.FromGeodetic(sourceCrs.ToGeodetic(p), sourceCrs.Ellipsoid));
                }

                return new ShapefileDataSource <object>(shapeFileName, spatialColumnName, srid, encoding, true, labelColumnName, func);
            }));
        }