The features in a map represent objects in the real world, each feature's relative location within the map reflects the location of that feature within the real world. The location of each feature is defined by use of a coordinate system.
Many different coordinate systems are used for data collection and storage. Using AspMap, there is a variety of ways you can view your data in a common coordinate system.
AspMap provides the CoordSystem class designed to allow the user to control and manipulate the coordinate system of data, when that data is displayed.
The CoordinateSystem property of each Layer should be set to the coordinate system in which a Layer’s underlying dataset is stored. It is necessary to know the coordinate system in which your dataset is defined:
A shapefile may have an accompanying coordinate system metadata file (.prj).
A TAB file may have an accompanying coordinate system metadata file (.tpj).
For shapefiles and TAB files (if the appropriate metadata is present) AspMap will read the information contained in the file and set the CoordinateSystem property of the Layer when the AddLayer method of a Map object is called. If the metadata is not present, or is incorrect, the CoordinateSystem property of a Layer can be manually set to any projected geographic coordinate system.
The CoordinateSystem property of a Map object defines the way in which the map layers are displayed on screen. Setting or changing the CoordinateSystem of a Map will change the coordinate system in which you view your data, as each layer is displayed in the Map object's CoordinateSystem. Image layers are not transformed.
The following sets a coordinate system (WorldMillerCylindrical) to the Map control as its output coordinate system, and another coordinate system (WGS84) as the source coordinate system of the Layer.
map1.CoordinateSystem = New AspMap.CoordSystem(CoordSystemCode.PCS_WorldMillerCylindrical) Dim layer As Layer = map1.AddLayer(MapPath("/maps/world.shp")) layer.CoordinateSystem = New AspMap.CoordSystem(CoordSystemCode.GCS_WGS84)
|Non-projected map (WGS84)||Projected map (WorldMillerCylindrical)|
Remember that setting the CoordinateSystem property of the Map will transform your data on-the-fly for the display only. You should bear this in mind when interacting with the original map. Consider the following:
The following sample transforms a point from the Map's coordinate system (WorldMillerCylindrical) to the Layer's coordinate system (WGS84) and searches for a polygon that contain the point. Then, it transforms the polygon into the Map's coordinate system and displays the polygon.
Protected Sub map_PointTool(ByVal sender As Object, ByVal e As PointToolEventArgs) Handles map.PointTool Dim layerPoint As AspMap.Point Dim worldLayer As AspMap.Layer = map1("world") ' transform the point to layer coordinates, ' from World Miller Cylindrical to WGS84 layerPoint = CoordSystem.Transform(map1.CoordinateSystem, e.Point, worldLayer.CoordinateSystem) ' perform search in WGS84 coordinates Dim rs As AspMap.Recordset = worldLayer.SearchShape(layerPoint, SearchMethod.PointInPolygon) If (Not rs.EOF) Then ' transform layer coordinates to map coordinates Dim shp As AspMap.Shape = CoordSystem.Transform(worldLayer.CoordinateSystem, rs.Shape, map1.CoordinateSystem) ' display the shape Dim ms As MapShape = map1.MapShapes.Add(shp) ms.Symbol.FillColor = Color.Yellow End If End Sub
© 2018 VDS Technologies
|Converted from CHM to HTML with chm2web Standard 2.85 (unicode)|