Example #1
0
        public static void Run()
        {
            //ExStart: ExportSpatialReferenceSystemToWKT
            var parameters = new ProjectedSpatialReferenceSystemParameters
            {
                Name = "WGS 84 / World Mercator",
                Base = SpatialReferenceSystem.Wgs84,
                ProjectionMethodName = "Mercator_1SP",
                LinearUnit           = Unit.Meter,
                XAxis       = new Axis("Easting", AxisDirection.East),
                YAxis       = new Axis("Northing", AxisDirection.North),
                AxisesOrder = ProjectedAxisesOrder.XY,
            };

            parameters.AddProjectionParameter("central_meridian", 0);
            parameters.AddProjectionParameter("scale_factor", 1);
            parameters.AddProjectionParameter("false_easting", 0);
            parameters.AddProjectionParameter("false_northing", 0);

            var projectedSrs = SpatialReferenceSystem.CreateProjected(parameters, Identifier.Epsg(3395));

            string wkt = projectedSrs.ExportToWkt();

            Console.WriteLine(wkt);
            //ExEnd: ExportSpatialReferenceSystemToWKT
        }
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir();

            //ExStart: CreateVectorLayerWithSpatialReferenceSystem
            var parameters = new ProjectedSpatialReferenceSystemParameters
            {
                Name = "WGS 84 / World Mercator",
                Base = SpatialReferenceSystem.Wgs84,
                ProjectionMethodName = "Mercator_1SP",
                LinearUnit           = Unit.Meter,
                XAxis       = new Axis("Easting", AxisDirection.East),
                YAxis       = new Axis("Northing", AxisDirection.North),
                AxisesOrder = ProjectedAxisesOrder.XY,
            };

            parameters.AddProjectionParameter("central_meridian", 0);
            parameters.AddProjectionParameter("scale_factor", 1);
            parameters.AddProjectionParameter("false_easting", 0);
            parameters.AddProjectionParameter("false_northing", 0);

            var projectedSrs = SpatialReferenceSystem.CreateProjected(parameters, Identifier.Epsg(3395));

            using (var layer = Drivers.Shapefile.CreateLayer(dataDir + "filepath_out.shp", new ShapefileOptions(), projectedSrs))
            {
                var feature = layer.ConstructFeature();
                feature.Geometry = new Point(1, 2);
                layer.Add(feature);

                feature          = layer.ConstructFeature();
                feature.Geometry = new Point(1, 2)
                {
                    SpatialReferenceSystem = SpatialReferenceSystem.Nad83
                };
                try
                {
                    layer.Add(feature); // geometry of feature has different SRS - exception is thrown
                }
                catch (GisException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            using (var layer = Drivers.Shapefile.OpenLayer(dataDir + "filepath_out.shp"))
            {
                var srsName = layer.SpatialReferenceSystem.Name;         // "WGS 84 / World Mercator"
                layer.SpatialReferenceSystem.IsEquivalent(projectedSrs); // true
            }
            //ExEnd: CreateVectorLayerWithSpatialReferenceSystem
        }