Ejemplo n.º 1
0
    private void TestMercator_2SP()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
        parameters.Add(new ProjectionParameter("central_meridian", 51));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem(
            "Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre,
            new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        Point pGeo = new Point(53, 53);
        Point pUtm = new Point(trans.MathTransform.Transform(pGeo.ToDoubleArray()));
        Point pGeo2 = new Point(trans.MathTransform.Inverse().Transform(pUtm.ToDoubleArray()));

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Point(165704.29, 5171848.07), pGeo2,
                                        "Mercator_2SP test");
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a UTM projection for the northern/// hemisphere based on the WGS84 datum
        /// </summary>
        /// <param name="utmZone">Utm Zone</param>
        /// <returns>Projection</returns>
        private IProjectedCoordinateSystem CreateUtmProjection(int utmZone)
        {
            CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

            //Create geographic coordinate system based on the WGS84 datum
            IEllipsoid                  ellipsoid = cFac.CreateFlattenedSphere("WGS 84", 6378137, 298.257223563, LinearUnit.Metre);
            IHorizontalDatum            datum     = cFac.CreateHorizontalDatum("WGS_1984", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs       = cFac.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, datum,
                                                                                          PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                          new AxisInfo("Lat", AxisOrientationEnum.North));

            //Create UTM projection
            List <ProjectionParameter> parameters = new List <ProjectionParameter>();

            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", -183 + 6 * utmZone));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new ProjectionParameter("false_easting", 500000));
            parameters.Add(new ProjectionParameter("false_northing", 0.0));
            IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters);

            return(cFac.CreateProjectedCoordinateSystem("WGS 84 / UTM zone " + utmZone.ToString() + "N", gcs,
                                                        projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East),
                                                        new AxisInfo("North", AxisOrientationEnum.North)));
        }
        public void TestAlbersProjectionFeet()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("central_meridian", -96));
            parameters.Add(new ProjectionParameter("latitude_of_center", 23));
            parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
            parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
            parameters.Add(new ProjectionParameter("false_easting", 0));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Foot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { -75, 35 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 1885472.7 / LinearUnit.Foot.MetersPerUnit, 1535925 / LinearUnit.Foot.MetersPerUnit };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.1), String.Format("Albers forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));
        }
Ejemplo n.º 4
0
    private void TestMercator_1SP()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
        parameters.Add(new ProjectionParameter("central_meridian", 110));
        parameters.Add(new ProjectionParameter("scale_factor", 0.997));
        parameters.Add(new ProjectionParameter("false_easting", 3900000));
        parameters.Add(new ProjectionParameter("false_northing", 900000));
        IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection,
                                                                                   LinearUnit.Metre,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(120, -3);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(5009726.58, 569150.82), pGeo2,
                                        "Mercator_1SP test");
    }
Ejemplo n.º 5
0
        private IProjectedCoordinateSystem createExpectedCoordinateSystem()
        {
            ICoordinateSystemFactory factory = new CoordinateSystemFactory<BufferedCoordinate2D>(
                _geoFactory.CoordinateFactory, _geoFactory);

            IEllipsoid grs80 = Ellipsoid.Grs80;

            IHorizontalDatum harn = factory.CreateHorizontalDatum(
                DatumType.HorizontalGeocentric, grs80, null, 
                "D_North_American_1983_HARN");

            IPrimeMeridian greenwich = PrimeMeridian.Greenwich;

            IAxisInfo axis0 = new AxisInfo(AxisOrientation.East, "Lon");
            IAxisInfo axis1 = new AxisInfo(AxisOrientation.North, "Lat");

            // Made the first parameter - the IExtents - null, which should be improved
            IGeographicCoordinateSystem gcs = factory.CreateGeographicCoordinateSystem(null,
                AngularUnit.Degrees, harn, greenwich, axis0, axis1, "GCS_North_American_1983_HARN");

            IProjection prj = factory.CreateProjection(
                "Lambert_Conformal_Conic",
                new ProjectionParameter[]
                    {
                        new ProjectionParameter("False_Easting", 8202099.737532808),
                        new ProjectionParameter("False_Northing", 0),
                        new ProjectionParameter("Central_Meridian", -120.5),
                        new ProjectionParameter("Standard_Parallel_1", 44.33333333333334),
                        new ProjectionParameter("Standard_Parallel_2", 46.0),
                        new ProjectionParameter("Latitude_Of_Origin", 43.66666666666666)
                    },
                "Lambert_Conformal_Conic");

            IProjectedCoordinateSystem expected = factory.CreateProjectedCoordinateSystem(
                gcs, prj, LinearUnit.Foot, axis0, axis1, "NAD_1983_HARN_StatePlane_Oregon_North_FIPS_3601");

            // TODO: Check if this is correct, since on line 184 of CoorindateSystemFactory.cs, 
            // HorizontalDatum is passed in as null
            return expected;
        }
Ejemplo n.º 6
0
    private void TestAlbers()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982,
                                                          LinearUnit.USSurveyFoot);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("central_meridian", -96));
        parameters.Add(new ProjectionParameter("latitude_of_origin", 23));
        parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
        parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs,
                                                                                   projection, LinearUnit.Metre,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(-75, 35);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(1885472.7, 1535925), pGeo2,
                                        "Albers Conical Equal Area test");
    }
Ejemplo n.º 7
0
    private void TestLambertConicConformal_2SP()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333));
        parameters.Add(new ProjectionParameter("central_meridian", -99));
        parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333));
        parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333));
        parameters.Add(new ProjectionParameter("false_easting", 2000000));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp",
                                                       parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs,
                                                                                   projection, LinearUnit.USSurveyFoot,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(-96, 28.5);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(2963503.91, 254759.80), pGeo2,
                                        "Lambert Conic Conformal 2SP test");
    }
Ejemplo n.º 8
0
    private void TestTransverseMercator()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
        parameters.Add(new ProjectionParameter("central_meridian", -2));
        parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
        parameters.Add(new ProjectionParameter("false_easting", 400000));
        parameters.Add(new ProjectionParameter("false_northing", -100000));
        IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid",
                                                                                   gcs, projection, LinearUnit.Metre,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(0.5, 50.5);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(577274.99, 69740.50), pGeo2,
                                        "Transverse Mercator test");
    }
Ejemplo n.º 9
0
        public override FeatureList process(FeatureList input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            // HACER ALGO DEL ESTILO:

            if (transform == null)
            {
                //Create zone UTM 32N projection
                IProjectedCoordinateSystem utmProj = CreateUtmProjection(32);

                //Create geographic coordinate system (lets just reuse the CS from the projection)
                IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem;

                //Create transformation
                CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

                // TODO DANI Mirar de donde viene este source y target
                ICoordinateTransformation Coordinatetransform = null;// TODO = ctFac.CreateFromCoordinateSystems(source, target);

                //cs
                string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
                //ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
                ICoordinateSystem cs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
                //wgs84
                GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

                //gcs
                CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
                //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();
                //Create Bessel 1840 geographic coordinate system
                IEllipsoid                  ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);
                IHorizontalDatum            datum     = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
                IGeographicCoordinateSystem gcs       = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
                                                                                              PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                                                                                              new AxisInfo("Lat", AxisOrientationEnum.North));

                //coordsys
                //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5);
                List <ProjectionParameter> parameters = new List <ProjectionParameter>();
                parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
                parameters.Add(new ProjectionParameter("central_meridian", 110));
                parameters.Add(new ProjectionParameter("scale_factor", 0.997));
                parameters.Add(new ProjectionParameter("false_easting", 3900000));
                parameters.Add(new ProjectionParameter("false_northing", 900000));
                IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);
                IProjectedCoordinateSystem coordsys =
                    cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre,
                                                         new AxisInfo("East", AxisOrientationEnum.East),
                                                         new AxisInfo("North", AxisOrientationEnum.North));

                Coordinatetransform = ctFac.CreateFromCoordinateSystems(gcs, coordsys);//gcsWGS84 -> gcenCsWGS84

                //Apply transformation
                transform = Coordinatetransform.MathTransform;
            }

            SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(30.0, 20.0);

            p = GeometryTransform.TransformPoint(p, transform);

/*IMPORTANTE
*           foreach (Feature feature in input)
*           {
*               feature.row.Geometry = GeometryTransform.TransformGeometry(feature.row.Geometry, transform);
*               //feature.row.Geometry = GeometryTransform.TransformMultiPolygon(feature.row.Geometry, transform);
*           }
*  IMPORTANTE*/
            foreach (Feature f in input)
            {
                output.Add(f);//output = input
            }

            // Cosas a cambiar:
            // Primero, la construccion del transform está siguiendo el ejemplo, pero hay que tener en cuenta los datos del xml y construirlo en consecuencia
            // Segundo, el filtro debe retornar una NUEVA lista, y no modificar la inicial. Ahora modifica los valores de la lista inicial
            // IMPORTANTE RETORNAR NUEVA LISTA OUTPUT <----------- FALTA POR HACER
#if TODO
            // first time through, establish a working SRS for output data.
            if (working_srs == null)
            {
                // first try to use the terrain SRS if so directed:
                SpatialReference new_out_srs = getUseTerrainSRS() ? env.getTerrainSRS() : null;
                if (new_out_srs == null)
                {
                    // failing that, see if we have an SRS in a resource:
                    if (getSRS() == null && getSRSScript() != null)
                    {
                        ScriptResult r = env.getScriptEngine().run(getSRSScript(), env);
                        if (r.isValid())
                        {
                            setSRS(env.getSession().getResources().getSRS(r.ToString()));
                        }
                        else
                        {
                            env.getReport().error(r.ToString());
                        }
                    }

                    new_out_srs = srs;
                }

                // set the "working" SRS that will be used for all features passing though this filter:
                working_srs = new_out_srs != null ? new_out_srs : env.getInputSRS();

                // LOCALIZE points around a local origin (the working extent's centroid)
                if (working_srs != null && getLocalize()) //&& env.getExtent().getArea() > 0.0 )
                {
                    if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179.0)
                    {
                        //NOP - no localization for big geog extent ... needs more thought perhaps
                    }
                    else
                    {
                        GeoPoint centroid0 = new_out_srs != null?
                                             new_out_srs.transform(env.getCellExtent().getCentroid()) :
                                                 env.getCellExtent().getCentroid();

                        // we do want the localizer point on the surface if possible:
                        GeoPoint centroid = clampToTerrain(centroid0, env);
                        if (centroid == null)
                        {
                            centroid = centroid0;
                        }

                        Matrixd localizer;

                        // For geocentric datasets, we need a special localizer matrix:
                        if (working_srs.isGeocentric())
                        {
                            localizer = working_srs.getEllipsoid().createGeocentricInvRefFrame(centroid);
                            localizer.invert(localizer);
                        }

                        // For projected datasets, just a simple translation:
                        else
                        {
                            localizer = osg.Matrixd.translate(-centroid);
                        }

                        working_srs = working_srs.cloneWithNewReferenceFrame(localizer);
                    }
                }
            }

            // we have to assign the output SRS on each pass
            if (working_srs != null)
            {
                env.setOutputSRS(working_srs);
            }

            return(base.process(input, env));
#endif
            //throw new NotImplementedException();

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList   l      = filter.process(output, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList   l      = filter.process(output, env);
                }
            }

            return(output);
        }
        public void TestTransverseMercator_Projection()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Airy 1830", 6377563.396, 299.32496, LinearUnit.Metre);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Airy 1830", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Airy 1830", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("latitude_of_origin", 49));
            parameters.Add(new ProjectionParameter("central_meridian", -2));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996012717));
            parameters.Add(new ProjectionParameter("false_easting", 400000));
            parameters.Add(new ProjectionParameter("false_northing", -100000));
            IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse_Mercator", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("OSGB 1936 / British National Grid", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { 0.5, 50.5 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 577274.99, 69740.50 };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("TransverseMercator forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("TransverseMercator reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
        }
        public void TestMercator_2SP_Projection()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
            parameters.Add(new ProjectionParameter("central_meridian", 51));
            parameters.Add(new ProjectionParameter("false_easting", 0));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { 53, 53 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 165704.29, 5171848.07 };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_2SP forward transformation outside tolerance, Expected {0}, got {1}", expected.ToString(), pUtm.ToString()));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_2SP reverse transformation outside tolerance, Expected {0}, got {1}", pGeo.ToString(), pGeo2.ToString()));
        }
        public void TestMercator_1SP_Projection_Feet()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", 110));
            parameters.Add(new ProjectionParameter("scale_factor", 0.997));
            parameters.Add(new ProjectionParameter("false_easting", 3900000 / LinearUnit.Foot.MetersPerUnit));
            parameters.Add(new ProjectionParameter("false_northing", 900000 / LinearUnit.Foot.MetersPerUnit));
            IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Foot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { 120, -3 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 5009726.58 / LinearUnit.Foot.MetersPerUnit, 569150.82 / LinearUnit.Foot.MetersPerUnit };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Mercator_1SP forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0],expected[1], pUtm[0],pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Mercator_1SP reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));
        }
        public void TestLambertConicConformal2SP_Projection()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 20925832.16, 294.97470, LinearUnit.USSurveyFoot);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("latitude_of_origin", 27.833333333));
            parameters.Add(new ProjectionParameter("central_meridian", -99));
            parameters.Add(new ProjectionParameter("standard_parallel_1", 28.3833333333));
            parameters.Add(new ProjectionParameter("standard_parallel_2", 30.2833333333));
            parameters.Add(new ProjectionParameter("false_easting", 2000000 / LinearUnit.USSurveyFoot.MetersPerUnit));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Lambert Conic Conformal (2SP)", "lambert_conformal_conic_2sp", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("NAD27 / Texas South Central", gcs, projection, LinearUnit.USSurveyFoot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { -96, 28.5 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 2963503.91 / LinearUnit.USSurveyFoot.MetersPerUnit, 254759.80 / LinearUnit.USSurveyFoot.MetersPerUnit };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.05), String.Format("LambertConicConformal2SP forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("LambertConicConformal2SP reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));
        }
        public void TestKrovak_Projection()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("latitude_of_center", 49.5));
            parameters.Add(new ProjectionParameter("longitude_of_center", 42.5));
            parameters.Add(new ProjectionParameter("azimuth", 30.28813972222222));
            parameters.Add(new ProjectionParameter("pseudo_standard_parallel_1", 78.5));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9999));
            parameters.Add(new ProjectionParameter("false_easting", 0));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Krovak", "Krovak", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("WGS 84", gcs, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            // test case 1
            double[] pGeo = new double[] { 12, 48 };
            double[] expected = new double[] { -953172.26, -1245573.32 };

            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Krovak forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Krovak reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));

            // test case 2
            pGeo = new double[] { 18, 49 };
            expected = new double[] { -499258.06, -1192389.16 };

            pUtm = trans.MathTransform.Transform(pGeo);
            pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.02), String.Format("Krovak forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Krovak reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a UTM projection for the northern/// hemisphere based on the WGS84 datum
        /// </summary>
        /// <param name="utmZone">Utm Zone</param>
        /// <returns>Projection</returns>
        private IProjectedCoordinateSystem CreateUtmProjection(int utmZone)
        {
            CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();

            //Create geographic coordinate system based on the WGS84 datum
            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("WGS 84", 6378137, 298.257223563, LinearUnit.Metre);
            IHorizontalDatum datum = cFac.CreateHorizontalDatum("WGS_1984", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS 84", AngularUnit.Degrees, datum,
              PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
              new AxisInfo("Lat", AxisOrientationEnum.North));

            //Create UTM projection
            List<ProjectionParameter> parameters = new List<ProjectionParameter>();
            parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new ProjectionParameter("central_meridian", -183 + 6 * utmZone));
            parameters.Add(new ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new ProjectionParameter("false_easting", 500000));
            parameters.Add(new ProjectionParameter("false_northing", 0.0));
            IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters);

            return cFac.CreateProjectedCoordinateSystem("WGS 84 / UTM zone " + utmZone.ToString() + "N", gcs,
               projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East),
               new AxisInfo("North", AxisOrientationEnum.North));
        }
Ejemplo n.º 16
0
        public override FeatureList process(FeatureList input, FilterEnv env)
        {
            FeatureList output = new FeatureList();

            // HACER ALGO DEL ESTILO:

            if (transform == null)
            {
                //Create zone UTM 32N projection
                IProjectedCoordinateSystem utmProj = CreateUtmProjection(32);

                //Create geographic coordinate system (lets just reuse the CS from the projection)
                IGeographicCoordinateSystem geoCS = utmProj.GeographicCoordinateSystem;

                //Create transformation
                CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

                // TODO DANI Mirar de donde viene este source y target
                ICoordinateTransformation Coordinatetransform = null;// TODO = ctFac.CreateFromCoordinateSystems(source, target);

                //cs
                string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
                //ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
                ICoordinateSystem cs = ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
                //wgs84
                GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

                //gcs
                CoordinateSystemFactory cFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
                //CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory();
                //Create Bessel 1840 geographic coordinate system
                IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);
                IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
                IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees, datum,
                    PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                    new AxisInfo("Lat", AxisOrientationEnum.North));

                //coordsys
                //Collection<ProjectionParameter> parameters = new Collection<ProjectionParameter>(5);
                List<ProjectionParameter> parameters = new List<ProjectionParameter>();
                parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
                parameters.Add(new ProjectionParameter("central_meridian", 110));
                parameters.Add(new ProjectionParameter("scale_factor", 0.997));
                parameters.Add(new ProjectionParameter("false_easting", 3900000));
                parameters.Add(new ProjectionParameter("false_northing", 900000));
                IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);
                IProjectedCoordinateSystem coordsys =
               cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection, LinearUnit.Metre,
                                                    new AxisInfo("East", AxisOrientationEnum.East),
                                                    new AxisInfo("North", AxisOrientationEnum.North));

                Coordinatetransform = ctFac.CreateFromCoordinateSystems(gcs, coordsys);//gcsWGS84 -> gcenCsWGS84

                //Apply transformation
                transform = Coordinatetransform.MathTransform;

            }

            SharpMap.Geometries.Point p = new SharpMap.Geometries.Point(30.0, 20.0);

            p = GeometryTransform.TransformPoint(p,transform);
/*IMPORTANTE
            foreach (Feature feature in input)
            {
                feature.row.Geometry = GeometryTransform.TransformGeometry(feature.row.Geometry, transform);
                //feature.row.Geometry = GeometryTransform.TransformMultiPolygon(feature.row.Geometry, transform);
            }
IMPORTANTE*/
            foreach (Feature f in input)
            {
                output.Add(f);//output = input
            }

            // Cosas a cambiar:
            // Primero, la construccion del transform está siguiendo el ejemplo, pero hay que tener en cuenta los datos del xml y construirlo en consecuencia
            // Segundo, el filtro debe retornar una NUEVA lista, y no modificar la inicial. Ahora modifica los valores de la lista inicial
            // IMPORTANTE RETORNAR NUEVA LISTA OUTPUT <----------- FALTA POR HACER
#if TODO
            // first time through, establish a working SRS for output data.
            if (working_srs == null)
            {
                // first try to use the terrain SRS if so directed:
                SpatialReference new_out_srs = getUseTerrainSRS() ? env.getTerrainSRS() : null;
                if (new_out_srs == null)
                {
                    // failing that, see if we have an SRS in a resource:
                    if (getSRS() == null && getSRSScript() != null)
                    {
                        ScriptResult r = env.getScriptEngine().run(getSRSScript(), env);
                        if (r.isValid())
                            setSRS(env.getSession().getResources().getSRS(r.ToString()));
                        else
                            env.getReport().error(r.ToString());
                    }

                    new_out_srs = srs;
                }

                // set the "working" SRS that will be used for all features passing though this filter:
                working_srs = new_out_srs != null ? new_out_srs : env.getInputSRS();

                // LOCALIZE points around a local origin (the working extent's centroid)
                if (working_srs != null && getLocalize()) //&& env.getExtent().getArea() > 0.0 )
                {
                    if (env.getCellExtent().getSRS().isGeographic() && env.getCellExtent().getWidth() > 179.0)
                    {
                        //NOP - no localization for big geog extent ... needs more thought perhaps
                    }
                    else
                    {
                        GeoPoint centroid0 = new_out_srs != null ?
                            new_out_srs.transform(env.getCellExtent().getCentroid()) :
                            env.getCellExtent().getCentroid();

                        // we do want the localizer point on the surface if possible:
                        GeoPoint centroid = clampToTerrain(centroid0, env);
                        if (centroid == null)
                            centroid = centroid0;

                        Matrixd localizer;

                        // For geocentric datasets, we need a special localizer matrix:
                        if (working_srs.isGeocentric())
                        {
                            localizer = working_srs.getEllipsoid().createGeocentricInvRefFrame(centroid);
                            localizer.invert(localizer);
                        }

                        // For projected datasets, just a simple translation:
                        else
                        {
                            localizer = osg.Matrixd.translate(-centroid);
                        }

                        working_srs = working_srs.cloneWithNewReferenceFrame(localizer);
                    }
                }
            }

            // we have to assign the output SRS on each pass
            if (working_srs != null)
            {
                env.setOutputSRS(working_srs);
            }

            return base.process(input, env);
#endif
            //throw new NotImplementedException();

            if (successor != null)
            {
                if (successor is FeatureFilter)
                {
                    FeatureFilter filter = (FeatureFilter)successor;
                    FeatureList l = filter.process(output, env);
                }
                else if (successor is FragmentFilter)
                {
                    FragmentFilter filter = (FragmentFilter)successor;
                    FragmentList l = filter.process(output, env);
                }
            }

            return output;
        }