understanding and using geometry, projections, and spatial...
TRANSCRIPT
Understanding and Using Geometry, Understanding and Using Geometry, Projections, and Spatial Reference Projections, and Spatial Reference
Systems in Systems in ArcGISArcGIS
MelitaMelita Kennedy, Rob Kennedy, Rob JuergensJuergens
IntroductionIntroduction
We present fundamental concepts necessary for the correct and efficient use of geometry and spatial reference APIs
• Spatial references and their properties• The geometry type system• Relational operators• Using geometry efficiently• What’s new at 10?
The Spatial Reference
Spatial referencesSpatial references
Spatial references in ArcGIS define these key properties:
• Coordinate system (projection) • Coordinate resolution grid• Cluster tolerances
In addition, geographic transformations move coordinates between different earth models
Accessing properties of spatial referencesAccessing properties of spatial references
• Python- Import arcpy- arcpy.Describe(“layer name”).SpatialReference.XYTolerance
• C#IMxDocument d = ArcMap.Document;
IFeatureLayer fl = (.) d.FocusMap.get_Layer(layer index);
IGeoDataset fcGridDS = (.) fl.FeatureClass;
ISpatialReferenceTolerance srt = (.)fcGridDS.SpatialReference;
MessageBox.Show(System.Convert.ToString(srt.XYTolerance));
Coordinate system objectsCoordinate system objects
• Projected (PCS)• Geographic (GCS)• Vertical (VCS)• Unknown (UCS)
• Units- Linear and Angular
• Geographic (datum) transformations
Datum
Spheroid
Prime Meridian
Projection Parameters
Projection
Projected Coordinate
System
Geographic Coordinate
System
Coordinate System
Angular Unit
Linear Unit
Well-Known Text string
GEOGCS[ "GCS_WGS_1984",DATUM[ "D_WGS_1984",
SPHEROID[ "WGS_1984", 6378137.0, 298.257223563] ],PRIMEM[ "Greenwich", 0.0],UNIT[ "Degree", 0.0174532925199433] ],
Read/write these strings via IESRISpatialReferenceGEN2
Well-Known Text string
PROJCS[ "Test",GEOGCS[ "GCS_WGS_1984",
DATUM[ "D_WGS_1984",SPHEROID[ "WGS_1984", 6378137.0, 298.257223563] ],
PRIMEM[ "Greenwich", 0.0],UNIT[ "Degree", 0.0174532925199433] ],
PROJECTION[ "Mercator " ],PARAMETER[ "Central_Meridian", -120.0], PARAMETER[ "Standard_Parallel_1", 0.0],PARAMETER[ "False_Easting", 500000.0],PARAMETER[ "False_Northing", 10000000.0],UNIT[ "Foot", 0.3048] ]
Geographic transformations
• “datum” transformations, geotransformations, GT• Convert between GCS• Includes unit, prime meridian, and spheroid changes• Defined in a particular direction• All are reversible
• Not all web APIs have full geotransformation support!
• Specify a GeoTransformation in these methods:- IGeometry5.ProjectEx5 Method – ArcObjects- Geometry Server Project method – SOAP- Currently no GT exposed via REST
ED50 versus WGS84
Multiple transformations between two GCSMultiple transformations between two GCS
PROJCS A2
GEOGCS A
PROJCS A1
Projection
(lon, lat)
(x, y)
(λ, φ)
Projection data flow
Projection using common GCS
ISpatialReferenceFactory3 sre =new SpatialReferenceEnvironmentClass();
IProjectedCoordinateSystempcs1 = sre.CreateProjectedCoordinateSystem(wkid1),pcs2 = sre.CreateProjectedCoordinateSystem(wkid2);
IGeometry g = <create a geometry somehow>g.SpatialReference = pcs1;
g.Project(pcs2);
GEOGCS A
PROJCS A1
GEOGCS B
PROJCS B1
Projection
Geographic Transformation
(lon, lat)
(x, y)
(λ, φ)
Projection with transformation data flow
Projection with GeoTransformation
ISpatialReferenceFactory3 sre =new SpatialReferenceEnvironmentClass();
IProjectedCoordinateSystem pcs1 = sre.CreateProjectedCoordinateSystem(wkid1),pcs2 = sre.CreateProjectedCoordinateSystem(wkid2);
IGeometry5 g = <create a geometry somehow>
IGeoTransformation gt = (.) sre.CreateGeoTransformation(GtWkid);
g.ProjectEx(pcs2, esriTransformDirection.esriTransformForward, gt, false, 10.0, 1.0);
Well-Known IDs
• Each object has an ID and a macro / enum- 4326- PE_GCS_WGS_1984- esriSRGeoCS_WGS1984
• IDs < 32766 are EPSG-assigned- EPSG Geodetic parameter Dataset, http://www.epsg.org
• IDs > 32767 are Esri-assigned• IDs may change
- ESRI EPSG- EPSG EPSG- Old IDs will still work
• ISpatialReference2GEN.FactoryCode
• Converts between NGA keyword and Esri WKID- ADI-A, HEN, NAS-C
int pe_nga_gt_code_to_factory_gt_code( const char *ncode);
const char *datum = "ADI-D";
int gt1_code = pe_nga_gt_code_to_factory_gt_code(datum);
• Can calculate error for the transformation
NGA datum converter
Projection Engine Add-ins
Web Mercator
• Online mapping services use a sphere-only Mercator
• Two ways to emulate it- Sphere-based GCS (102113)- Projection that can force sphere equations (102100 or 3857)
• Mathematically EQUAL
• It distorts distances and areas
The Spatial Reference (tolerance & resolution)
Coordinate resolution gridCoordinate resolution grid
• Data sources except shapefiles snap to this grid when storing features
• Where points can be placed• Start with a horizon polygon• Put a square over it• Slice it horizontally and vertically• High precision (lots of slices, today)
- versus basic precision (not so many slices, legacy)
• Majority of ArcGIS operations snap to this grid
Ex: Horizon and Grid for NAD 1983 UTM Zone 11Ex: Horizon and Grid for NAD 1983 UTM Zone 11
False Origin:Xmin = -5,136,135 m Ymin = -9,950,490 m
Xmax = 14,890,535 m Ymax = 9,992,387 m
XY resolution = 2.2 x 10-9 m(finest resolution, smallest extent)
…
……
Coordinate resolution grid properties exampleCoordinate resolution grid properties example
ISpatialReference sr = ArcMap.Document.FocusMap.SpatialReference;
WKSPoint falseOrigin;double xyUnits, resolution;
sr.GetFalseOriginAndUnits (out falseOrigin.X, out falseOrigin.Y, out xyUnits);
resolution = 1.0 / xyUnits; // resolution is ground distance between grid lines
Cluster toleranceCluster tolerance
• Used for consistent spatial decisions with vector data- With an iterative procedure called integration (AKA cracking /
clustering)
• Tolerance = 1/10th minimum separation between geometries
• Resolution = 1/10th tolerance
• Default tolerance = 1.0 mm• Default resolution = 0.1 mm
ISpatialReferenceTolerance.XYTolerance
Visualizing the coordinate grid
Geometry
Core geometry typesCore geometry types
• “Top Level Types” can be stored in a geodatabase or shapefile
- Points- Multipoints- Polylines- Polygons- Multipatches
• Polylines are sequences of Paths• Polygons are sequences of Rings• Paths and rings are sequences of Segments
- Lines- Circular and elliptical arcs- Bezier curves
Coordinate access interfacesCoordinate access interfaces
• IPointCollection- Treat ring, path, polyline, or polygon as a set of points - Add, remove, or iterate over vertices
• ISegmentCollection- Treat as a set of segments
• IGeometryCollection- References to parts of multipoints, polylines, polygons- GeometryBag
• Reduces memory footprint• Efficient access
Enumerator exampleEnumerator example
IEditSketch es = (.) ArcMap.Application.FindExtensionByName(
"ESRI Object Editor");
ISegmentCollection segs = (.) es.Geometry;IEnumSegment segEnum = segs.EnumSegments;ISegment seg;int iPart = 0, iSeg = 0;segEnum.Next(out seg, ref iPart, ref iSeg);while (seg != null)
segEnum.Next(out seg, ref iPart, ref iSeg);
• Vertex enumerators are similar• Update properties (x,y,z,m,id) of existing vertices and segments
Geometry Service
• D/COM access via GeoDatabase .NET assembly
• Access from any client via SOAP or REST
Geometry environment thread singletonGeometry environment thread singleton
• Creates (empty) objects
• Sets thread global variables like default densification tolerance
Geometry environment example
// Export and Import WKB format
IPoint p = new PointClass();
p.PutCoords(1.0, 1.0);
IWkb pw = (IWkb) p;
int cBytes = pw.WkbSize;
byte [] aBytes = new byte[cBytes];
pw.ExportToWkb(ref cBytes, out aBytes[0]);
IGeometryFactory3 ge = new GeometryEnvironmentClass();
IGeometry outG;
ge.CreateGeometryFromWkb(ref cBytes, ref aBytes[0], out outG);
IPoint outP = (.) outG;
Other objectsOther objects
• Geometry Bags- anything that supports the IGeometry interface
• WKSPoint (structure)• Transformation objects
- pass a transformation to a geometry
ITransform2D geometryToBeTransformed = …
IAffineTransformation2D T = new AffineTransformation2DClass();
T.Move(1.0, 1.0);
geometryToBeTransformed.Transform (esriTransformDirection. esriTransformForward, T);
Simple geometriesSimple geometries
• Multipoints- each point must be unique
• Polylines- segment length > resolution, - vertical lines permitted when z-aware
• Polygons – uses cluster tolerance - definite inside-outside-boundary- finite area- multiple rings, outer: clockwise, inner: counter-clockwise
- Rings can touch at points- note difference between connected and outer components
Enforcing simplicityEnforcing simplicityFor low level objects
• Multipoints- ITopologicalOperator::Simplify
• Polylines- IPolyline6::SimplifyNonPlanar (10.0)- IPolyline::SimplifyNetwork (merges valence two parts)
• Polygons- ITopologicalOperator::Simplify- SimplifyPreserveFromTo, less efficient
Enforcing simplicityFor higher level objects
• IFeatureSimplify::SimplifyGeometry- If Polygon, simplify (preserve from / to)- Project to dataset (doesn’t clear isSimple bit)- Simplify again
- preserve from / to for polygons- non-planar for polylines- snap to grid for points / multipoints
Relational operatorsRelational operators
• 5 core operators - defined in terms of interior, boundary, exterior
• Point has an interior only• Polyline
- boundary is set of path endpoints- interior is everything except the endpoints - we do not planarize before applying this definition
• Polygon - boundary is rings - interior is the inside of rings
Relational operators (cont.)Relational operators (cont.)
• Disjoint – boundary and interiors disjoint• In – the usual, but interior intersection can’t be empty
- same for contains
• Touch – shapes are not disjoint but interiors are• Cross – interior intersection dimension is < max dimension
of inputs- no containment
• Overlap – interior intersection dimension = dimension of inputs
- no containment
• IRelationalOperator.Disjoint, Contains, Crosses…
Contains examples
Overlap examples
TipsTips
• Always tag geometry with a spatial reference• Tag geometry bag with an sr before adding geometries to it• Know when you’re sharing references to rings / paths /
segments• Shapefiles can’t store curves, vertex IDs, or some
properties of Multipatches (e.g. textures)
• Use point and segment enumerators to access existing polylines and polygons (recycling)
• Use array-based methods (IGeometryBridge/2) to add data to geometries
• Use WKSPoint structures when possible • Watch your object burn rate
What’s new at 10
WhatWhat’’s new at 10.0?s new at 10.0?
• Geometry server methods - support web editing- some geodesic operations (distance, length)
• http://servicesbeta.esri.com/arcgis/sdk/soap/• http://servicesbeta.esri.com/ArcGIS/rest/services/Geometr
y/GeometryServer
• Vertical segments in polylines
WhatWhat’’s new at 10.0? (cont)s new at 10.0? (cont)
• Geodetic constructions- IConstructGeodetic- IPolycurveGeodetic
• Exposed in- Editor UI- Measurement tool UI
WhatWhat’’s new example: Geodesic ellipsess new example: Geodesic ellipses
IConstructGeodetic.ConstructGeodesicEllipse (centerPoint, linearUnit, semiMajor, semiMinor, majorAz, esriCurveDensifyMethod.esriCurveDensifyByDeviation, 1.0);
What’s new at 10 (cont.)
Notation transformation• Supported notations
- MGRS - Military Grid Reference System
- USNG - US National Grid
- UTM - Universal Transverse Mercator
- GEOREF - Geographic Reference System
- GARS - Global Area Reference System
- DMS - Degree Minute Second
- DDM - Degree Decimal-Minute
- DD - Decimal Degree
• Conversions- Notation to coordinates- Coordinates to notation
• Point::IConversionNotation
Coming up in the Projection Engine…
• Native C# (.NET) API- Win32 and Compact Framework
• C++ API- wrapper around C API
• Updated and improved Java API- separate engine and factory- improved performance- previous version available but deprecated
• Consistent API across all languages• C API unchanged!
ResourcesResources
• ESRI Technical paper: Understanding Coordinate Management in the Geodatabase
• ESRI Technical paper: Understanding Geometric Processing in ArcGIS
• Clementini, et al. A small set of formal topological relationships suitable for end-user interaction
More resources
• ArcGIS Desktop help, Professional Library- Map Projections Guide Book
- Data Management Editing Data Fundamentals of editing About editing data in a different projection (projecting on the fly).
• Resolution and tolerance default values
• ArcObjects SDK help- Geometry library overview topic
- Working with vertical polyline segments (accessible from geometry library overview topic)
Other recommended sessionsOther recommended sessions……
• ArcGIS 10.1 and the Road Ahead- Thu 8:30 am - Primrose B (Palm Springs Convention Center)
• Working with Image Services - Thu 8:30 am - Catalina/Madera (Renaissance Hotel)
• The File Geodatabase API- Thu 10:15 am - Primrose B (Palm Springs Convention Center)
Questions?
Please fill out the session survey.
Thank you!