Exemplo n.º 1
0
        public static IEnumerable <GeometryData> Load(PointFile source)
        {
            var fact = new GeometryFactory();

            using StreamReader reader = File.OpenText(source.Filename);

            var options = new CsvOptions {
                HeaderMode = source.HeaderMode,
                RowsToSkip = source.RowsToSkip,
                Separator  = source.Separator[0]
            };

            CoordinateSystem f = ProjectionUtils.Transforms[source.Srid];
            CoordinateSystem t = ProjectionUtils.EPSG_4326();

            foreach (var row in CsvReader.Read(reader, options).Take(source.MaxRecords ?? int.MaxValue))
            {
                double.TryParse(row[source.Latitude], out double latitude);
                double.TryParse(row[source.Longitude], out double longitude);
                var geom = new Coordinate(longitude, latitude);

                geom = geom.Transform(f, t);

                var data = new GeometryData
                {
                    DataType  = source.DataType,
                    Geom      = fact.CreatePoint(geom),
                    Name      = row[source.Name],
                    Reference = source.Reference != null ? row[(int)source.Reference] : null,
                };
                yield return(data);
            }
        }
        public static IEnumerable <GeometryData> Load(PolygonFile source)
        {
            var geomFact = new GeometryFactory();

            using var reader = new ShapefileDataReader(source.Filename, geomFact);

            CoordinateSystem f = ProjectionUtils.Transforms[source.Srid];
            CoordinateSystem t = ProjectionUtils.EPSG_4326();
            var transformer    = ProjectionUtils.GetTransformer(f, t);

            while (reader.Read())
            {
                var    name      = reader.GetString(source.Name);
                string reference = null;

                if (source.Reference != null)
                {
                    reference = reader.GetString((int)source.Reference);
                }

                if (reference == null)
                {
                    reference = Guid.NewGuid().ToString();
                }

                var geom = ProjectionUtils.Transform(reader.Geometry, transformer);

                var data = new GeometryData {
                    Name = name, DataType = source.DataType, Reference = reference, Geom = geom
                };

                yield return(data);
            }
        }