Exemplo n.º 1
0
        private double[] TransformToUTM(SharpGis.SharpGps.Coordinate p)
        {
            //For fun, let's use the SharpMap transformation library and display the position in UTM
            int zone = (int)Math.Floor((p.Longitude + 183) / 6.0);

            SharpMap.CoordinateSystems.ProjectedCoordinateSystem proj = SharpMap.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, (p.Latitude >= 0));
            SharpMap.CoordinateSystems.Transformations.ICoordinateTransformation trans =
                new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(proj.GeographicCoordinateSystem, proj);
            double[] result = trans.MathTransform.Transform(new double[] { p.Longitude, p.Latitude });
            return(new double[] { result[0], result[1], zone });
        }
      private SharpMap.Geometries.Point ProyectarPunto(double longitud, double latitud)
      {
        // Aca deberia proyectar desde lat/lon a UTM.
        SharpMap.CoordinateSystems.IProjectedCoordinateSystem UTM = CreateUTMProjection(1);
        
        //Create geographic coordinate system (lets just reuse the CS from the projection)
        SharpMap.CoordinateSystems.IGeographicCoordinateSystem geoCS = UTM.GeographicCoordinateSystem;
        //Create transformation
        SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFac = new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory();
        SharpMap.CoordinateSystems.Transformations.ICoordinateTransformation transform = ctFac.CreateFromCoordinateSystems(geoCS, UTM);
        
        //Apply transformation to a vectorlayer
        SharpMap.Geometries.Point pt = SharpMap.CoordinateSystems.Transformations.GeometryTransform.TransformPoint(new SharpMap.Geometries.Point(longitud, latitud), transform.MathTransform);

        return pt;
      }
		public void TestTransformAllWKTs()
		{
			//GeographicCoordinateSystem.WGS84
			SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory fact = new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory();
			CoordinateSystemFactory fac = new CoordinateSystemFactory();
			int parsecount = 0;
			System.IO.StreamReader sr = System.IO.File.OpenText(@"..\..\SRID.csv");
			string line = "";
			while (!sr.EndOfStream)
			{
				line = sr.ReadLine();
				int split = line.IndexOf(';');
				if (split > -1)
				{
					string srid = line.Substring(0, split);
					string wkt = line.Substring(split + 1);
					ICoordinateSystem cs = SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
					if (cs == null) continue; //We check this in another test.
					if (cs is IProjectedCoordinateSystem)
					{
						switch ((cs as IProjectedCoordinateSystem).Projection.ClassName)
						{
							//Skip not supported projections
							case "Oblique_Stereographic": 
							case "Transverse_Mercator_South_Orientated":
							case "Hotine_Oblique_Mercator":
							case "Lambert_Conformal_Conic_1SP":
							case "Krovak":
							case "Cassini_Soldner":
							case "Lambert_Azimuthal_Equal_Area":
							case "Tunisia_Mining_Grid":
							case "New_Zealand_Map_Grid":
							case "Polyconic":
							case "Lambert_Conformal_Conic_2SP_Belgium":
							case "Polar_Stereographic":
								continue;
							default: break;
						}
					}
					try
					{
						SharpMap.CoordinateSystems.Transformations.ICoordinateTransformation trans = fact.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, cs);
					}
					catch (System.Exception ex)
					{
						if (cs is IProjectedCoordinateSystem)
							Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message + "\r\nClass name:" + (cs as IProjectedCoordinateSystem).Projection.ClassName);
						else
							Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message);						
					}
					parsecount++;
				}
			}
			sr.Close();
			Assert.AreEqual(parsecount, 2536, "Not all WKT was processed");
		}
Exemplo n.º 4
0
 private double[] TransformToUTM(SharpGis.SharpGps.Coordinate p)
 {
     //For fun, let's use the SharpMap transformation library and display the position in UTM
     int zone = (int)Math.Floor((p.Longitude + 183) / 6.0);
     SharpMap.CoordinateSystems.ProjectedCoordinateSystem proj = SharpMap.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, (p.Latitude >= 0));
     SharpMap.CoordinateSystems.Transformations.ICoordinateTransformation trans =
         new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory().CreateFromCoordinateSystems(proj.GeographicCoordinateSystem, proj);
     double[] result = trans.MathTransform.Transform(new double[] { p.Longitude, p.Latitude });
     return new double[] { result[0], result[1], zone };
 }
Exemplo n.º 5
0
        private void Initialize()
        {
            GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel precisionModel =
                new GisSharpBlog.NetTopologySuite.Geometries.PrecisionModel(GeoAPI.Geometries.PrecisionModels.Floating);

            SharpMap.CoordinateSystems.CoordinateSystem wgs84 = SharpMap.CoordinateSystems.GeographicCoordinateSystem.WGS84;

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

            List <GeoAPI.CoordinateSystems.ProjectionParameter> parameters =
                new List <GeoAPI.CoordinateSystems.ProjectionParameter>();

            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("latitude_of_origin", 0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("central_meridian", 117));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("scale_factor", 0.9996));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("false_easting", 500000));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("false_northing", 10000000));
            GeoAPI.CoordinateSystems.IProjection projection = cFac.CreateProjection("Transverse Mercator", "Transverse Mercator", parameters);

            GeoAPI.CoordinateSystems.IProjectedCoordinateSystem utmWGS84 = cFac.CreateProjectedCoordinateSystem("WGS84 UTM Zone 50S",
                                                                                                                gcsWGS84, projection, SharpMap.CoordinateSystems.LinearUnit.Metre,
                                                                                                                new GeoAPI.CoordinateSystems.AxisInfo("East", GeoAPI.CoordinateSystems.AxisOrientationEnum.East),
                                                                                                                new GeoAPI.CoordinateSystems.AxisInfo("North", GeoAPI.CoordinateSystems.AxisOrientationEnum.North));

            int SRID_utm50 = Convert.ToInt32(utmWGS84.AuthorityCode);    //UTM50 SRID

            SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact =
                new SharpMap.CoordinateSystems.Transformations.CoordinateTransformationFactory();

            _Transform    = ctFact.CreateFromCoordinateSystems(utmWGS84, wgs84);
            _UTM50Factory = new GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory(precisionModel, SRID_utm50);
        }