public void CreateBasicTransform() { using (var pc = new ProjContext()) { using (var crs1 = CoordinateReferenceSystem.Create("EPSG:25832", pc)) using (var crs2 = CoordinateReferenceSystem.Create("EPSG:25833", pc)) { Assert.AreEqual(ProjType.ProjectedCrs, crs1.Type); Assert.AreEqual(ProjType.ProjectedCrs, crs2.Type); using (var t = CoordinateTransform.Create(crs1, crs2)) { CoordinateTransformList steps = t as CoordinateTransformList; Assert.IsNotNull(steps); Assert.AreEqual(2, steps.Count); Assert.AreEqual("Inverse of Transverse Mercator", steps[0].MethodName); Assert.AreEqual("Transverse Mercator", steps[1].MethodName); Assert.AreEqual("Inverse of UTM zone 32N + UTM zone 33N", t.Name); using (var tr = t.CreateInverse()) { Assert.AreEqual("Inverse of UTM zone 33N + UTM zone 32N", tr.Name); } } using (var t = CoordinateTransform.Create(crs2, crs1)) { Assert.AreEqual("Inverse of UTM zone 33N + UTM zone 32N", t.Name); } } } }
private Boolean ExecuteTransform( CoordinateReferenceSystem srcCRS, CoordinateReferenceSystem tgtCRS) { _srcPt.X = _srcOrd1; _srcPt.Y = _srcOrd2; // Testing: flip axis order to test SS sample file // srcPt.x = srcOrd2; // srcPt.y = srcOrd1; var trans = CtFactory.CreateTransform(srcCRS, tgtCRS); trans.Transform(_srcPt, _resultPt); var dx = Math.Abs(_resultPt.X - _tgtOrd1); var dy = Math.Abs(_resultPt.Y - _tgtOrd2); var dz = 0d; if (!Double.IsNaN(_tolOrd3)) { dz = Math.Abs(_resultPt.Z - _tgtOrd3); } _isInTol = dx <= _tolOrd1 && dy <= _tolOrd2; if (dz != 0) { _isInTol |= (!double.IsNaN(dz) && dz <= _tolOrd3); } return(_isInTol); }
public void TestCopenhagen() { var ctx = new ProjContext(); var src = CoordinateReferenceSystem.Create("EPSG:4326", ctx); var dst = CoordinateReferenceSystem.Create(/*"+proj=utm +zone=32 +datum=WGS84" or */ "EPSG:32632", ctx); Assert.AreEqual("WGS 84", src.Name); Assert.AreEqual("WGS 84 / UTM zone 32N", dst.Name); var t = CoordinateTransform.Create(src, dst, ctx); var t2 = CoordinateTransform.Create(src.WithAxisNormalized(), dst.WithAxisNormalized(), ctx); var p = t2.ApplyReversed(new double[] { 12, 55 }); Trace.WriteLine($"Easting: {p[0]}, Northing: {p[1]}"); var r = t2.ApplyReversed(p); Trace.WriteLine($"Longitude: {r[0]}, Latitude: {r[1]}"); var tt = CoordinateTransform.Create(src, src, null); Assert.AreEqual("Null geographic offset from WGS 84 to WGS 84", tt.Name); var ss = ctx.Create("+proj=utm +zone=32 +datum=WGS84 +ellps=clrk66"); }
private static Boolean CheckTransform(String csName, double lon, double lat, double expectedX, double expectedY, double tolerance) { CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); CoordinateReferenceSystemFactory csFactory = new CoordinateReferenceSystemFactory(); /* * Create {@link CoordinateReferenceSystem} & CoordinateTransformation. * Normally this would be carried out once and reused for all transformations */ CoordinateReferenceSystem crs = csFactory.CreateFromName(csName); const String wgs84Param = "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees"; CoordinateReferenceSystem wgs84 = csFactory.CreateFromParameters("WGS84", wgs84Param); ICoordinateTransform trans = ctFactory.CreateTransform(wgs84, crs); /* * Create input and output points. * These can be constructed once per thread and reused. */ ProjCoordinate p = new ProjCoordinate(); ProjCoordinate p2 = new ProjCoordinate(); p.X = lon; p.Y = lat; /* * Transform point */ trans.Transform(p, p2); return(IsInTolerance(p2, expectedX, expectedY, tolerance)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void comparePointsMustOnlyReturnZeroForEqualPoints() internal virtual void ComparePointsMustOnlyReturnZeroForEqualPoints() { PointValue firstPoint = _random.randomValues().nextPointValue(); PointValue equalPoint = Values.point(firstPoint); CoordinateReferenceSystem crs = firstPoint.CoordinateReferenceSystem; SpaceFillingCurve curve = _noSpecificIndexSettings.forCrs(crs, false); long? spaceFillingCurveValue = curve.DerivedValueFor(firstPoint.Coordinate()); PointValue centerPoint = Values.pointValue(crs, curve.CenterPointFor(spaceFillingCurveValue.Value)); GenericKey firstKey = NewKeyState(); firstKey.WriteValue(firstPoint, NEUTRAL); GenericKey equalKey = NewKeyState(); equalKey.WriteValue(equalPoint, NEUTRAL); GenericKey centerKey = NewKeyState(); centerKey.WriteValue(centerPoint, NEUTRAL); GenericKey noCoordsKey = NewKeyState(); noCoordsKey.WriteValue(equalPoint, NEUTRAL); GeometryType.NoCoordinates = noCoordsKey; assertEquals(0, firstKey.CompareValueTo(equalKey), "expected keys to be equal"); assertEquals(firstPoint.CompareTo(centerPoint) != 0, firstKey.CompareValueTo(centerKey) != 0, "expected keys to be equal if and only if source points are equal"); assertEquals(0, firstKey.CompareValueTo(noCoordsKey), "expected keys to be equal"); }
public bool CheckTransformToGeo(String name, double x, double y, double lon, double lat, double tolerance) { CoordinateReferenceSystem crs = CreateCRS(name); CoordinateReferenceSystem geoCRS = crs.CreateGeographic(); return(CheckTransform(crs, x, y, geoCRS, lon, lat, tolerance)); }
public void TestExplicitTransform() { const String csName1 = "EPSG:32636"; const String csName2 = "EPSG:4326"; CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); CoordinateReferenceSystemFactory csFactory = new CoordinateReferenceSystemFactory(); /* * Create {@link CoordinateReferenceSystem} & CoordinateTransformation. * Normally this would be carried out once and reused for all transformations */ CoordinateReferenceSystem crs1 = csFactory.CreateFromName(csName1); CoordinateReferenceSystem crs2 = csFactory.CreateFromName(csName2); ICoordinateTransform trans = ctFactory.CreateTransform(crs1, crs2); /* * Create input and output points. * These can be constructed once per thread and reused. */ ProjCoordinate p1 = new ProjCoordinate(); ProjCoordinate p2 = new ProjCoordinate(); p1.X = 500000; p1.Y = 4649776.22482; /* * Transform point */ trans.Transform(p1, p2); Assert.IsTrue(IsInTolerance(p2, 33, 42, 0.000001)); }
internal override Value AsValue(GenericKey state) { AssertHasCoordinates(state); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get(( int )state.Long1, ( int )state.Long2); return(AsValue(state, crs, 0)); }
public void CRSFactoryTest() { CoordinateReferenceSystemFactory crsFactory = new CoordinateReferenceSystemFactory(); CoordinateReferenceSystem crsSource = crsFactory.CreateFromName("EPSG:4326"); Assert.IsNotNull(crsSource); Assert.AreEqual("EPSG:4326", crsSource.Name); CoordinateReferenceSystem crsTarget = crsFactory.CreateFromParameters("EPSG:3875", "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"); Assert.IsNotNull(crsTarget); Assert.AreEqual("EPSG:3875", crsTarget.Name); BasicCoordinateTransform t = new BasicCoordinateTransform(crsSource, crsTarget); ProjCoordinate prjSrc = new ProjCoordinate(0, 0); ProjCoordinate prjTgt = new ProjCoordinate(); t.Transform(prjSrc, prjTgt); BasicCoordinateTransform t2 = new BasicCoordinateTransform(crsTarget, crsSource); ProjCoordinate prjTgt2 = new ProjCoordinate(); t2.Transform(prjTgt, prjTgt2); Assert.AreEqual(0d, prjSrc.Distance(prjTgt2)); }
public CoordinateHelper() { using (Stream stream = new FileStream("./systems.xlsx", FileMode.Open)) { string proj4, dX, name, dY, cM = ""; using (ExcelPackage excel = new ExcelPackage(stream, "Fgh8DjhEashKl5")) { var worksheet = excel.Workbook.Worksheets.First(); for (int i = 2; true; i++) { name = worksheet.Cells["A" + i].Text; if (name == "") { break; } else { dX = worksheet.Cells["B" + i].Text; dY = worksheet.Cells["C" + i].Text; cM = worksheet.Cells["D" + i].Text; proj4 = "+proj=tmerc +lat_0=0 +lon_0=" + cM + " +k=1 +x_0=" + dX + " +y_0=" + dY + " +ellps=krass +towgs84=23.57,-140.95,-79.8,0,0.35,0.79,-0.22 +units=m +no_defs"; refSystems.Add(name, proj4); } } } } geographSystem = crFac.CreateFromParameters("wsg84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"); }
public ReferencedEnvelope(double minY, double maxY, double minX, double maxX, CoordinateReferenceSystem cordRef) { _minY = minY; _maxY = maxY; _minX = minX; _maxX = maxX; _cordRef = cordRef; }
internal EnvelopeSettings(CoordinateReferenceSystem crs) { this._crs = crs; this._min = new double[crs.Dimension]; this._max = new double[crs.Dimension]; Arrays.fill(this._min, Double.NaN); Arrays.fill(this._max, Double.NaN); }
/// <summary> /// Initializes a new instance of the <see cref="GeocentricTranslation" /> class. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="name">The name.</param> /// <param name="remarks">The remarks.</param> /// <param name="aliases">The aliases.</param> /// <param name="parameters">The parameters of the operation.</param> /// <param name="source">The source coordinate reference system.</param> /// <param name="target">The target coordinate reference system.</param> /// <param name="areaOfUse">The area of use.</param> /// <exception cref="System.ArgumentNullException"> /// The identifier is null. /// or /// The source coordinate reference system is null. /// or /// The target coordinate reference system is null. /// or /// The area of use is null. /// </exception> public GeocentricTranslation(String identifier, String name, String remarks, String[] aliases, IDictionary <CoordinateOperationParameter, Object> parameters, CoordinateReferenceSystem source, CoordinateReferenceSystem target, AreaOfUse areaOfUse) : base(identifier, name, remarks, aliases, CoordinateOperationMethods.GeocentricTranslationGeocentricDomain, parameters, source, target, areaOfUse) { this.xAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.XAxisTranslation); this.yAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.YAxisTranslation); this.zAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.ZAxisTranslation); }
internal SpatialFile(CoordinateReferenceSystem crs, ConfiguredSpaceFillingCurveSettingsCache configuredSettings, File indexDirectory) { this.Crs = crs; this.ConfiguredSettings = configuredSettings; string s = crs.Table.TableId + "-" + Convert.ToString(crs.Code); this.IndexFile = new File(indexDirectory, s); }
public Boolean Execute(CoordinateReferenceSystemFactory csFactory) { _srcCRS = CreateCRS(csFactory, _srcCrsAuth, _srcCrs); _tgtCRS = CreateCRS(csFactory, _tgtCrsAuth, _tgtCrs); var isOK = ExecuteTransform(_srcCRS, _tgtCRS); return(isOK); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.values.storable.PointValue unpackPoint3D() throws java.io.IOException internal virtual PointValue UnpackPoint3D() { int crsCode = UnpackInteger(); CoordinateReferenceSystem crs = CoordinateReferenceSystem.get(crsCode); double[] coordinates = new double[] { UnpackDouble(), UnpackDouble(), UnpackDouble() }; return(pointValue(crs, coordinates)); }
internal static PointValue AsValue(GenericKey state, CoordinateReferenceSystem crs, int offset) { double[] coordinates = new double[Dimensions(state)]; for (int i = 0; i < coordinates.Length; i++) { coordinates[i] = Double.longBitsToDouble(state.Long1Array[offset + i]); } return(Values.pointValue(crs, coordinates)); }
/// <summary>${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_D}</summary> /// <returns>${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_return}</returns> /// <param name="indexX">${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_param_indexX}</param> /// <param name="indexY">${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_param_indexY}</param> /// <param name="resolution">${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_param_resolution}</param> /// <param name="cancellationToken">${WP_Mapping_TiledDynamicRESTLayer_method_GetTileUrl_param_cancellationToken}</param> public override MapImage GetTile(int indexX, int indexY, double resolution, CancellationToken cancellationToken) { double scale = 0; scale = ScaleHelper.ScaleConversion(resolution, this.Dpi, this.CRS); string str = string.Empty; str = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}/tileImage.{1}?scale={2}&x={3}&y={4}&width={5}&height={5}&transparent={6}&t={7}", Url, ImageFormat.ToLower(), scale.ToString(CultureInfo.InvariantCulture), indexX, indexY, TileSize, Transparent, _randomKey); if (!EnableServerCaching) { str += string.Format("&cacheEnabled={0}", EnableServerCaching.ToString(System.Globalization.CultureInfo.InvariantCulture).ToLower()); } if (!string.IsNullOrEmpty(LayersID)) { str += string.Format("&layersID={0}", layersID); } if (ClipRegion != null) { str += "&clipRegionEnabled=True&"; str += string.Format("clipRegion={0}", JsonConvert.SerializeObject(ClipRegion.ToServerGeometry())); } if (MaxVisibleVertex != int.MaxValue && MaxVisibleVertex >= 0) { str += string.Format(System.Globalization.CultureInfo.InvariantCulture, "&maxVisibleVertex={0}", MaxVisibleVertex); } if (!Point2D.IsNullOrEmpty(this.Origin)) { // origin={"x":-200,"y":45}, str += "&origin={" + string.Format(CultureInfo.InvariantCulture, "\"x\":{0},\"y\":{1}", this.Origin.X, this.Origin.Y) + "}"; } //iServer tileImage请求中只要存在prjCoordSys参数就会把图片生成到temp目录下, //所以如果CRS和服务端一致,就不传这个参数上去了。 if (this.mapService != null && this.mapService.LastResult != null && this.mapService.LastResult.PrjCoordSys != null) { CoordinateReferenceSystem tempCRS = new CoordinateReferenceSystem(); if (_mapServiceDefault.LastResult != null) { tempCRS.WKID = this._mapServiceDefault.LastResult.PrjCoordSys.EpsgCode; tempCRS.Unit = this._mapServiceDefault.LastResult.CoordUnit; } if (!CoordinateReferenceSystem.Equals(tempCRS, this.CRS, true)) { if (this.CRS != null && this.CRS.WKID > 0) { str += "&prjCoordSys={\"epsgCode\":" + this.CRS.WKID + "}"; } } } str += string.Format("&customParams={0}", CustomParams); MapImage image = new MapImage(); image.MapImageType = MapImageType.Url; image.Url = str; return image; }
internal PartAccessor(PageCache pageCache, FileSystemAbstraction fs, SpatialIndexFiles.SpatialFileLayout fileLayout, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor, SpaceFillingCurveConfiguration searchConfiguration, bool readOnly) : base(pageCache, fs, fileLayout.IndexFile, fileLayout.Layout, monitor, descriptor, NO_HEADER_WRITER, readOnly) { this.Layout = fileLayout.Layout; this.Descriptor = descriptor; this.SearchConfiguration = searchConfiguration; this.Crs = fileLayout.SpatialFile.crs; this.Settings = fileLayout.Settings; instantiateTree(recoveryCleanupWorkCollector, HeaderWriter); }
/// <summary> /// Gets a managed coordinate transformation for the specified coordinate reference systems. /// </summary> /// <param name="source">The source coordinate reference system.</param> /// <param name="target">The source coordinate reference system.</param> /// <returns>The managed coordinate transformation, provided through <see cref="ICoordinateTransformation"/>.</returns> /// <exception cref="TransformationNotFoundException">Thrown if no transformation is available to transform coordinates /// from the specified source to the specified target coordinate reference system.</exception> public new static ICoordinateTransformation Get(CoordinateReferenceSystem source, CoordinateReferenceSystem target) { if (source == null || target == null) { throw new TransformationNotFoundException(source.getId(), target.getId()); } return(Get(source.getId(), target.getId())); }
private static SridItem WithinWriteLock_Register(CoordinateReferenceSystem crs, int withSrid) { SridItem added = new SridItem(withSrid, crs); _registered.Add(crs, added); _catalog.Add(withSrid, added); return(added); }
internal virtual void WritePointDerived(CoordinateReferenceSystem crs, long derivedValue, NativeIndexKey.Inclusion inclusion) { if (IsArray) { throw new System.InvalidOperationException("This method is intended to be called when querying, where one or more sub-ranges are derived " + "from a queried range and each sub-range written to separate keys. " + "As such it's unexpected that this key state thinks that it's holds state for an array"); } UpdateCurve(crs.Table.TableId, crs.Code); setType(Types.Geometry).write(this, derivedValue, _noCoordinates); this.Inclusion = inclusion; }
/// <summary> /// Initializes a new instance of the <see cref="CoordinateTransformation"/> class. /// </summary> /// <param name="sourceId">Identifier of the source coordinate reference system.</param> /// <param name="targetId">Identifier of the target coordinate reference system.</param> private CoordinateTransformation(string sourceId, string targetId) { source = Registry.Get(sourceId); target = Registry.Get(targetId); if (source == null || !source.Valid || target == null || !target.Valid) { throw new TransformationNotFoundException(sourceId, targetId); } }
/// <summary> /// Initializes a new instance of the <see cref="CoordinateTransformation"/> class. /// </summary> /// <param name="source">Source coordinate reference system.</param> /// <param name="target">Target coordinate reference system.</param> private CoordinateTransformation(CoordinateReferenceSystem source, CoordinateReferenceSystem target) { this.source = source; this.target = target; if (source == null || !source.Valid || target == null || !target.Valid) { throw new TransformationNotFoundException(source.getId(), target.getId()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writePoint(org.neo4j.values.storable.CoordinateReferenceSystem crs, double[] coordinate) throws RuntimeException public override void WritePoint(CoordinateReferenceSystem crs, double[] coordinate) { Append("{geometry: {type: \"Point\", coordinates: "); Append(Arrays.ToString(coordinate)); Append(", crs: {type: link, properties: {href: \""); Append(crs.Href); Append("\", code: "); Append(Convert.ToString(crs.Code)); Append("}}}}"); }
/// <summary> /// Initializes a new instance of the <see cref="SimilarityTransformation" /> class. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="name">The name.</param> /// <param name="remarks">The remarks.</param> /// <param name="aliases">The aliases.</param> /// <param name="parameters">The parameters of the operation.</param> /// <param name="source">The source coordinate reference system.</param> /// <param name="target">The target coordinate reference system.</param> /// <param name="areaOfUse">The area of use.</param> /// <exception cref="System.ArgumentNullException"> /// The identifier is null. /// or /// The source coordinate reference system is null. /// or /// The target coordinate reference system is null. /// or /// The area of use is null. /// </exception> public SimilarityTransformation(String identifier, String name, String remarks, String[] aliases, IDictionary <CoordinateOperationParameter, Object> parameters, CoordinateReferenceSystem source, CoordinateReferenceSystem target, AreaOfUse areaOfUse) : base(identifier, name, remarks, aliases, CoordinateOperationMethods.SimilarityTransformation, parameters, source, target, areaOfUse) { this.ordinate1OfEvaluationPointInTarget = this.GetParameterValue(CoordinateOperationParameters.Ordinate1OfEvaluationPointInTarget); this.ordinate2OfEvaluationPointInTarget = this.GetParameterValue(CoordinateOperationParameters.Ordinate2OfEvaluationPointInTarget); this.scaleDifference = this.GetParameterValue(CoordinateOperationParameters.ScaleDifference); this.rotationAngleOfSourceCoordinate = this.GetParameterBaseValue(CoordinateOperationParameters.XAxisRotation); this.m = 1 + this.scaleDifference * 1E-6; }
// TODO: provide limit on number of items in cache (LRU) /// <summary> /// /// </summary> /// <param name="name"></param> /// <returns></returns> ///<exception cref="UnsupportedParameterException"/> /// <exception cref="InvalidValueException"></exception> ///<exception cref="UnknownAuthorityCodeException"></exception> public CoordinateReferenceSystem CreateFromName(String name) { CoordinateReferenceSystem proj = null;//(CoordinateReferenceSystem) ProjCache.get(name); if (ProjCache.TryGetValue(name, out proj)) { proj = CrsFactory.CreateFromName(name); ProjCache.Add(name, proj); } return(proj); }
/// <summary> /// Initializes a new instance of the <see cref="MolodenskyTransformation" /> class. /// </summary> /// <param name="identifier">The identifier.</param> /// <param name="name">The name.</param> /// <param name="remarks">The remarks.</param> /// <param name="aliases">The aliases.</param> /// <param name="parameters">The parameters of the operation.</param> /// <param name="source">The source coordinate reference system.</param> /// <param name="target">The target coordinate reference system.</param> /// <param name="ellipsoid">The ellipsoid.</param> /// <param name="areaOfUse">The area of use.</param> /// <exception cref="System.ArgumentNullException"> /// The source coordinate reference system is null. /// or /// The target coordinate reference system is null. /// or /// The ellipsoid is null. /// or /// The area of use is null. /// </exception> protected MolodenskyTransformation(String identifier, String name, String remarks, String[] aliases, IDictionary <CoordinateOperationParameter, Object> parameters, CoordinateReferenceSystem source, CoordinateReferenceSystem target, Ellipsoid ellipsoid, AreaOfUse areaOfUse) : base(identifier, name, remarks, aliases, CoordinateOperationMethods.MolodenskyTransformation, parameters, source, target, areaOfUse) { this.Ellipsoid = ellipsoid ?? throw new ArgumentNullException(nameof(ellipsoid)); this.xAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.XAxisTranslation); this.yAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.YAxisTranslation); this.zAxisTranslation = this.GetParameterValue(CoordinateOperationParameters.ZAxisTranslation); this.semiMajorAxisLengthDifference = this.GetParameterValue(CoordinateOperationParameters.SemiMajorAxisLengthDifference); this.flatteningDifference = this.GetParameterValue(CoordinateOperationParameters.FlatteningDifference); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void writePoint(org.neo4j.values.storable.CoordinateReferenceSystem crs, double[] coordinate) throws IllegalArgumentException public override void WritePoint(CoordinateReferenceSystem crs, double[] coordinate) { if (AllowStorePointsAndTemporal) { Block.ValueBlocks = GeometryType.encodePoint(KeyId, crs, coordinate); } else { throw new UnsupportedFormatCapabilityException(Capability.POINT_PROPERTIES); } }
internal SridItem(int srid, CoordinateReferenceSystem crs) { if (crs is null) { throw new ArgumentNullException(nameof(crs)); } SRID = srid; CRS = crs; _factory = new Lazy <GeometryFactory>(() => NtsGeometryServices.Instance.CreateGeometryFactory(srid)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <param name="creator"></param> /// <param name="preferredSrid"></param> /// <returns></returns> public static SridItem Ensure <T>(T value, Func <CoordinateReferenceSystem> creator, int?preferredSrid) where T : struct, Enum { if (preferredSrid.HasValue && preferredSrid == 0) { throw new ArgumentOutOfRangeException(nameof(preferredSrid)); } if (TryGetById(value, out var item)) { return(item); } CoordinateReferenceSystem crs = creator(); using (_rwl.WithWriteLock()) { if (_registered.ContainsKey(crs)) { throw new ArgumentException("CRS instance already registered", nameof(crs)); } try { item = null; if (preferredSrid.HasValue && _catalog.TryGetValue(preferredSrid.Value, out item)) { if (item.CRS.IsEquivalentTo(crs)) { return(item); } preferredSrid = null; } if (preferredSrid.HasValue) { item = WithinWriteLock_Register(crs, preferredSrid.Value); } else { item = WithinWriteLock_Register(crs); } return(item); } finally { if (item != null) { WithingWriteLock_TryRegisterId(item, value); } } } }
public static double ScaleConversion(double referResolution, double dpi, CoordinateReferenceSystem crs) { if (crs != null) { return ScaleConversion(referResolution, dpi, crs.Unit, crs.DatumAxis); } else { return ScaleConversion(referResolution, dpi); } }
private void ShouldGetSettingsFor(Config config, CoordinateReferenceSystem crs, int dimensions, int maxBits, Envelope envelope) { ConfiguredSpaceFillingCurveSettingsCache configuredSettings = new ConfiguredSpaceFillingCurveSettingsCache(config); SpaceFillingCurveSettings settings = configuredSettings.ForCRS(crs); assertThat("Expected " + dimensions + "D for " + crs.Name, settings.Dimensions, equalTo(dimensions)); int maxLevels = maxBits / dimensions; assertThat("Expected maxLevels=" + maxLevels + " for " + crs.Name, settings.MaxLevels, equalTo(maxLevels)); assertThat("Should have normal geographic 2D extents", settings.IndexExtents(), equalTo(envelope)); }
/// <summary>${WP_utility_ScaleHelper_method_GetSmDpi_D}</summary> /// <remarks>${WP_utility_ScaleHelper_method_GetSmDpi_remarks}</remarks> /// <param name="referViewBounds">${WP_utility_ScaleHelper_method_GetSmDpi_param_referViewBounds}</param> /// <param name="referViewer">${WP_utility_ScaleHelper_method_GetSmDpi_param_referViewer}</param> /// <param name="referScale">${WP_utility_ScaleHelper_method_GetSmDpi_param_referScale}</param> /// <param name="crs">${WP_utility_ScaleHelper_method_GetSmDpi_param_crs}</param> public static double GetSmDpi(Rectangle2D referViewBounds, Rect referViewer, double referScale, CoordinateReferenceSystem crs) { CoordinateReferenceSystem tempCRS = crs; if (tempCRS == null) { tempCRS = new CoordinateReferenceSystem(); } if (tempCRS.DatumAxis <= 0) { tempCRS.DatumAxis = 6378137; } if (tempCRS.Unit == Unit.Undefined) { tempCRS.Unit = Unit.Degree; } int ratio = 10000; double num1 = referViewBounds.Width / referViewer.Width;//横向分辨率 double num2 = referViewBounds.Height / referViewer.Height;//纵向分辨率 if (crs.Unit == Unit.Degree) { double referResolution = num1 > num2 ? num1 : num2;//取横向或纵向分辨率中的较大者,用于计算DPI var dpi = 0.0254 * ratio / referResolution / referScale / ((Math.PI * 2 * crs.DatumAxis) / 360) / ratio; return dpi; } else { var dpi = 0.0254 * ratio / num1 / referScale / ratio; return dpi; } }
/// <summary>${utility_ScaleHelper_method_ScaleConversion_D}</summary> /// <param name="input">${utility_ScaleHelper_method_ScaleConversion_param_input}</param> /// <param name="dpi">${utility_ScaleHelper_method_ScaleConversion_param_dpi}</param> /// <param name="crs">${utility_ScaleHelper_method_ScaleConversion_param_crs}</param> /// <returns>${utility_ScaleHelper_method_ScaleConversion_return}</returns> public static double ScaleConversion(double input, double dpi, CoordinateReferenceSystem crs) { CoordinateReferenceSystem tempCRS = crs; if (tempCRS == null) { tempCRS = new CoordinateReferenceSystem(); } if (tempCRS.DatumAxis <= 0) { tempCRS.DatumAxis = 6378137; } if (tempCRS.Unit == Unit.Undefined) { tempCRS.Unit = Unit.Degree; } if (dpi > 0.0 && input > 0.0) { if (tempCRS.Unit == Unit.Degree) { input *= ((Math.PI * 2 * tempCRS.DatumAxis) / 360); } var scale = 0.0254 / input / dpi; return scale; } return double.NaN; }
private void ParseCapabilities(XDocument document) { string ns = document.Root.Name.NamespaceName; if (document.Root.Attribute("version") != null) { this.Version = document.Root.Attribute("version").Value; } var type = (from Service in document.Descendants(XName.Get("Service", ns)) select new WMSLayerInfo { Title = (Service.Element(XName.Get("Title", ns)) == null) ? null : Service.Element(XName.Get("Title", ns)).Value, Abstract = (Service.Element(XName.Get("Abstract", ns)) == null) ? null : Service.Element(XName.Get("Abstract", ns)).Value, Name = (Service.Element(XName.Get("Name", ns)) == null) ? null : Service.Element(XName.Get("Name", ns)).Value }).First(); if (type != null) { this.Metadata.Add("Name", type.Name); this.Metadata.Add("Title", type.Title); this.Metadata.Add("Abstract", type.Abstract); } //获取Layer信息; foreach (WMSLayerInfo info in from Layers in document.Descendants(XName.Get("Layer", ns)) where Layers.Descendants(XName.Get("Layer", ns)).Count<XElement>() == 0 select new WMSLayerInfo { Name = (Layers.Element(XName.Get("Name", ns)) == null) ? null : Layers.Element(XName.Get("Name", ns)).Value, Title = (Layers.Element(XName.Get("Title", ns)) == null) ? null : Layers.Element(XName.Get("Title", ns)).Value, Abstract = (Layers.Element(XName.Get("Abstract", ns)) == null) ? null : Layers.Element(XName.Get("Abstract", ns)).Value, Bounds = GetBounds(Layers.Element(XName.Get("BoundingBox", ns))) } ) { this.AllLayerList.Add(info); } //try //{ // XElement element = (from c in (from c in document.Descendants(XName.Get("Capability", ns)) select c).First<XElement>().Descendants(XName.Get("Request", ns)) select c).First<XElement>(); // //this.httpGetResource = (from c in element.Descendants(XName.Get("OnlineResource", ns)) select c).First<XElement>().Attribute(XName.Get("href", "http://www.w3.org/1999/xlink")).Value; //} //catch //{ // //this.Url = this.httpGetResource; //} IEnumerable<XElement> source = document.Descendants(XName.Get("BoundingBox", ns)); if (!source.GetEnumerator().MoveNext() && this.LowerThan13Version()) { XElement element = document.Descendants(XName.Get("BoundingBox", ns)).First<XElement>(); CRS = new CoordinateReferenceSystem(4326); this.Bounds = GetBounds(element); } if (CRS == null) { string str = this.LowerThan13Version() ? "SRS" : "CRS"; foreach (XElement element in source) { if (element.Attribute((XName)str) != null && element.Attribute((XName)str).Value.StartsWith("EPSG:")) { try { int wkid = int.Parse(element.Attribute((XName)str).Value.Replace("EPSG:", ""), CultureInfo.InvariantCulture); CRS = new CoordinateReferenceSystem(wkid); } catch { } this.Bounds = GetBounds(element); break; } } if (this.Bounds.IsEmpty) { XElement element = source.First<XElement>(); if (element.Attribute((XName)str) != null) { string s = element.Attribute((XName)str).Value; int startIndex = s.LastIndexOf(":"); if (startIndex > -1) { s = s.Substring(startIndex + 1); } try { int num = int.Parse(s, CultureInfo.InvariantCulture); CRS = new CoordinateReferenceSystem(num); } catch { } } this.Bounds = GetBounds(element); } } }
/// <summary>${mapping_GetWMTSCapabilities_method_GetCRS_D}</summary> internal CoordinateReferenceSystem GetCRS(XElement elmt) { CoordinateReferenceSystem crs = new CoordinateReferenceSystem(); if (elmt != null) { string value = elmt.Value; string[] temp = value.Trim().Split(':'); if (temp != null) { int wkid = int.Parse(temp.Last(), CultureInfo.InvariantCulture); crs.WKID = wkid; } } return crs; }
private void mapService_Initialized() { if (mapService.LastResult != null) { if (base.Error != null) { base.Initialize(); } else { if (CRS == null) { CRS = new CoordinateReferenceSystem(); if (this.mapService.LastResult != null) { CRS.Unit = this.mapService.LastResult.CoordUnit; if (mapService.LastResult.PrjCoordSys != null) { CRS.WKID = mapService.LastResult.PrjCoordSys.EpsgCode; if (mapService.LastResult.PrjCoordSys.CoordSystem != null && mapService.LastResult.PrjCoordSys.CoordSystem.Datum != null && mapService.LastResult.PrjCoordSys.CoordSystem.Datum.Spheroid != null) { CRS.DatumAxis = mapService.LastResult.PrjCoordSys.CoordSystem.Datum.Spheroid.Axis; } } } } Bounds = this.mapService.LastResult.Bounds; Dpi = ScaleHelper.GetSmDpi(this.mapService.LastResult.ViewBounds, this.mapService.LastResult.Viewer, this.mapService.LastResult.Scale, CRS); Dpi *= AdjustFactor; base.Initialize(); } } }
//TODO:需要改,没用好 internal static double[] ConversionBetweenScalesAndResulotions(double[] temp, double dpi, CoordinateReferenceSystem crs) { if (crs == null) { crs = new CoordinateReferenceSystem(); } if (crs.Unit == Unit.Undefined) { crs.Unit = Unit.Degree; } if (crs.DatumAxis <= 0) { crs.DatumAxis = 6378137; } if (dpi > 0 && temp != null && temp.Length > 0) { double[] numArray = new double[temp.Length]; for (int i = 0; i < temp.Length; i++) { numArray[i] = ScaleConversion(temp[i], dpi,crs); } return numArray; } return null; }
/// <summary> /// ${utility_ScaleHelper_method_GetSmDpi_D}</summary> /// <remarks>${utility_ScaleHelper_method_GetSmDpi_remarks}</remarks> /// <param name="referViewBounds">${utility_ScaleHelper_method_GetSmDpi_param_referViewBounds}</param> /// <param name="referViewer">${utility_ScaleHelper_method_GetSmDpi_param_referViewer}</param> /// <param name="referScale">${utility_ScaleHelper_method_GetSmDpi_param_referScale}</param> /// <param name="crs">${utility_ScaleHelper_method_GetSmDpi_param_crs}</param> /// <returns>${utility_ScaleHelper_method_GetSmDpi_return}</returns> public static double GetSmDpi(Rectangle2D referViewBounds, Rect referViewer, double referScale, CoordinateReferenceSystem crs) { CoordinateReferenceSystem tempCRS = crs; if (tempCRS == null) { tempCRS = new CoordinateReferenceSystem(); } if (tempCRS.DatumAxis <= 0) { tempCRS.DatumAxis = 6378137; } if (tempCRS.Unit == Unit.Undefined) { tempCRS.Unit = Unit.Degree; } int ratio = 10000; //10000 是 0.1毫米与米的转换,底层UGC有个int变换,换回去即可 //double nD1 = referViewBounds.Width * ratio * referScale;//逻辑宽度(单位:0.1毫米),比例尺=图上距离:实际距离, //这里所计算的即为referViewBounds.width代表的图上宽度。 //int nD3 = (nD1 > 0.0) ? (int)(nD1 + 0.5) : (int)(nD1 - 0.5);//判断当前地图单位是否为经纬度,若逻辑宽度nD1的值介于-0.5~0.5之间,则认为地图单位为经纬度 double num1 = referViewBounds.Width / referViewer.Width;//横向分辨率 double num2 = referViewBounds.Height / referViewer.Height;//纵向分辨率 //地图单位为经纬度 if (tempCRS.Unit == Unit.Degree) { double referResolution = num1 > num2 ? num1 : num2;//取横向或纵向分辨率中的较大者,用于计算DPI var dpi = 0.0254 * ratio / referResolution / referScale / ((Math.PI * 2 * tempCRS.DatumAxis) / 360) / ratio; return dpi; } else { var dpi = 0.0254 * ratio / num1 / referScale / ratio; return dpi; } }
/// <summary>${Mapping_TiledDynamicRESTLayer_method_Initialize_D}</summary> public override void Initialize() { if (!this.isInitializing && !base.IsInitialized) { if (string.IsNullOrEmpty(this.Url)) { //Error = new ArgumentNullException(SuperMap.Web.iServerJava6R.Resources.ExceptionStrings.InvalidUrl); Initialize(); return; } if (IsSkipGetSMMapServiceInfo) { if (Bounds.IsEmpty) { Error = new ArgumentNullException("Bounds"); } Dpi = ScaleHelper.GetSmDpi(ReferViewBounds, ReferViewer, ReferScale); Dpi *= AdjustFactor; this.isInitializing = true; base.Initialize(); return; } this.isInitializing = true; EventHandler<SuperMap.Connector.Utility.MapParameterEventArgs> completed = (sender, e) => { if (base.Error != null) { base.Initialize(); } else { if (CRS == null) { CRS = new CoordinateReferenceSystem { Unit = (Core.Unit)e.MapParameter.CoordUnit, WKID = e.MapParameter.PrjCoordSys.EpsgCode }; } Bounds = new Rectangle2D(e.MapParameter.Bounds.LeftBottom.X, e.MapParameter.Bounds.LeftBottom.Y, e.MapParameter.Bounds.RightTop.X, e.MapParameter.Bounds.RightTop.Y); Dpi = ScaleHelper.GetSmDpi(new Rectangle2D(e.MapParameter.ViewBounds.LeftBottom.X, e.MapParameter.ViewBounds.LeftBottom.Y, e.MapParameter.ViewBounds.RightTop.X, e.MapParameter.ViewBounds.RightTop.Y), new Rect(0, 0, e.MapParameter.Viewer.Width, e.MapParameter.Viewer.Height), e.MapParameter.Scale); Dpi *= AdjustFactor; base.Initialize(); } }; EventHandler<SuperMap.Connector.Utility.FailedEventArgs> failed = (sender, e) => { base.Error = e.Exception; base.Initialize(); }; string[] splitItems = this.Url.Split(new char[] { '/' }); string mapName = splitItems[splitItems.Length - 1]; int restIndex = this.Url.LastIndexOf("maps"); string compomentUrl = this.Url.Substring(0, restIndex); SuperMap.Connector.Map map = new Connector.Map(compomentUrl); map.GetDefaultMapParameter(mapName, false, completed, failed); } }
private void mapService_Initialized(object sender, SmMapService.MapServiceInitalizeArgs e) { if (e.MapService.MapServiceUrl == this.Url.Trim()) { if (base.Error != null) { base.Initialize(); } else { if (CRS == null) { CRS = new CoordinateReferenceSystem { }; if (this.mapService.MapServiceInfo != null) { CRS.Unit = this.mapService.MapServiceInfo.CoordUnit; if (this.mapService.MapServiceInfo.PrjCoordSys != null) { CRS.WKID = this.mapService.MapServiceInfo.PrjCoordSys.EpsgCode; if (this.mapService.MapServiceInfo.PrjCoordSys.CoordSystem != null && this.mapService.MapServiceInfo.PrjCoordSys.CoordSystem.Datum != null && this.mapService.MapServiceInfo.PrjCoordSys.CoordSystem.Datum.Spheroid != null) { CRS.DatumAxis = this.mapService.MapServiceInfo.PrjCoordSys.CoordSystem.Datum.Spheroid.Axis; } } } } Bounds = this.mapService.MapServiceInfo.Bounds; Dpi = ScaleHelper.GetSmDpi(this.mapService.MapServiceInfo.ViewBounds, this.mapService.MapServiceInfo.Viewer, this.mapService.MapServiceInfo.Scale, CRS.Unit, CRS.DatumAxis); Dpi *= AdjustFactor; this.ReferScale = this.mapService.MapServiceInfo.Scale; this.ReferViewBounds = this.mapService.MapServiceInfo.ViewBounds; this.ReferViewer = this.mapService.MapServiceInfo.Viewer; base.Initialize(); } } }
//TODO:需要改,没用好 internal static double[] ConversionBetweenScalesAndResulotions(double[] temp, double dpi, CoordinateReferenceSystem crs) { if (dpi > 0 && temp != null && temp.Length > 0) { double[] numArray = new double[temp.Length]; for (int i = 0; i < temp.Length; i++) { numArray[i] = ScaleConversion(temp[i], dpi, crs); } return numArray; } return null; }