/// <summary> /// Assigns projection to the layer if the layer doesn't have one. /// </summary> public void AssignProjection(ISpatialReference proj) { if (proj == null) { throw new ArgumentNullException("proj"); } _image.GeoProjection = proj.Clone().GetInternal(); }
public void SetSpatialReferences(ISpatialReference from, ISpatialReference to) { if (from == null) { lock (LockThis1) { try { if (_fromID != IntPtr.Zero) { Proj4Wrapper.pj_free(_fromID); } } catch { } _fromID = IntPtr.Zero; _fromSRef = null; } } if (to == null) { lock (LockThis1) { try { if (_toID != IntPtr.Zero) { Proj4Wrapper.pj_free(_toID); } } catch { } _toID = IntPtr.Zero; _toSRef = null; } } if ((from != null && from.Datum == null) && (to != null && to.Datum != null)) { ISpatialReference toSRef = (ISpatialReference)to.Clone(); toSRef.Datum = null; this.ToSpatialReference = toSRef; this.FromSpatialReference = from; } else if ((from != null && from.Datum != null) && (to != null && to.Datum == null)) { this.ToSpatialReference = to; ISpatialReference fromSRef = (ISpatialReference)from.Clone(); fromSRef.Datum = null; this.FromSpatialReference = fromSRef; } else { this.ToSpatialReference = to; this.FromSpatialReference = from; } }
public void SetSpatialReferences(ISpatialReference from, ISpatialReference to) { if (from == null) { this.FromSpatialReference = from; } if (to == null) { this.ToSpatialReference = to; } if ((from != null && from.Datum == null) && (to != null && to.Datum != null)) { ISpatialReference toSRef = (ISpatialReference)to.Clone(); toSRef.Datum = null; this.ToSpatialReference = toSRef; this.FromSpatialReference = from; } else if ((from != null && from.Datum != null) && (to != null && to.Datum == null)) { this.ToSpatialReference = to; ISpatialReference fromSRef = (ISpatialReference)from.Clone(); fromSRef.Datum = null; this.FromSpatialReference = fromSRef; } else { this.ToSpatialReference = to; this.FromSpatialReference = from; } _projectionPipeline = ProjectionPipeline(_fromSrs, _toSrs); _basicCoordinateTransformations = new BasicCoordinateTransform[_projectionPipeline.Length - 1]; _basicCoordinateTransformationsInverse = new BasicCoordinateTransform[_projectionPipeline.Length - 1]; for (int p = 0, p_to = _projectionPipeline.Length; p < p_to - 1; p++) { BasicCoordinateTransform t = new BasicCoordinateTransform(_projectionPipeline[p], _projectionPipeline[p + 1]); _basicCoordinateTransformations[p] = t; } for (int p = _projectionPipeline.Length; p > 1; p--) { BasicCoordinateTransform t = new BasicCoordinateTransform(_projectionPipeline[p - 1], _projectionPipeline[p - 2]); _basicCoordinateTransformationsInverse[_projectionPipeline.Length - p] = t; } }
/// <summary> /// Assigns laye projection to the map. /// </summary> private TestingResult HandleEmptyMapProjection(ISpatialReference layerProj) { var db = _context.Projections; if (db != null) { var cs = db.GetCoordinateSystem(layerProj, ProjectionSearchType.UseDialects); if (cs != null) { var proj = new SpatialReference(); if (proj.ImportFromEpsg(cs.Code)) { layerProj = proj; } } } _context.Map.Projection = layerProj.Clone(); return(TestingResult.Ok); }
private void btnGetSRef_Click(object sender, EventArgs e) { ISpatialReference sRef = (cmbSRef.SelectedItem is SpatialReferenceItem) ? ((SpatialReferenceItem)cmbSRef.SelectedItem).SpatialReference : null; FormSpatialReference dlg = new FormSpatialReference(sRef.Clone() as ISpatialReference); if (dlg.ShowDialog() == DialogResult.OK) { if (dlg.SpatialReference != null && (sRef == null || !dlg.SpatialReference.Equals(sRef))) { SpatialReferenceItem item = new SpatialReferenceItem(dlg.SpatialReference); _items.Add(item); cmbSRef.Items.Add(item); cmbSRef.SelectedItem = item; } } }