GSuite WPF Edition Quick Start Guide Welcome to GSuite WPF Edition from Mapgenix, a powerful .Net control for custom development of WPF (Windows Presentation Foundation) Desktop applications. The aim of this guide is to help the developer get started with building a simple WPF mapping app. It comes with code in C#. Along the way, many concepts of GIS and mapping are explained with links to specific guides to learn more. This guide is divided into two main parts: I) Installing trial version of GSuite WPF edition It shows how to download the sample apps and install the Mapgenix dlls from NuGet. There is also a video for it Installing trial version of GSuite WPF Edition. II) My first app using GSuite WPF edition It shows how to create your first WPF app from scratch using GSuite WPF edition. There is also a video for it My First App using GSuite WPF edition. To get the most of this guide, you will find three separate sections with different colors to distinguish from the main text.
25
Embed
GSuite WPF Edition Quick Start Guide - Mapgenix GSuite · GSuite WPF Edition Quick Start Guide ... -DotSpatial.Projections -DotSpatial.Serialization ... get the scale of the map,
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
GSuite WPF Edition Quick Start Guide
Welcome to GSuite WPF Edition from Mapgenix, a powerful .Net control for custom
development of WPF (Windows Presentation Foundation) Desktop applications. The aim of this
guide is to help the developer get started with building a simple WPF mapping app. It comes
with code in C#. Along the way, many concepts of GIS and mapping are explained with links to
specific guides to learn more.
This guide is divided into two main parts:
I) Installing trial version of GSuite WPF edition
It shows how to download the sample apps and install the Mapgenix dlls from NuGet.
There is also a video for it Installing trial version of GSuite WPF Edition.
II) My first app using GSuite WPF edition
It shows how to create your first WPF app from scratch using GSuite WPF edition.
There is also a video for it My First App using GSuite WPF edition.
To get the most of this guide, you will find three separate sections with different colors to
distinguish from the main text.
Code
In a blue frame is code to follow to complete the exercises.
After purchasing the full version of GSuite, you will receive a new key to place in that same App.config file. This will allow GSuite to run permanently and without water marks on the map.
4) Build Solution (F6)
5) Add the Map Control to the ToolBox
(You need to be in Designer View)
- Choose Item…
- Browse…
Browse to the bin directory of your application and select
Mapgenix.GSuite.Wpf.dll
Reminder
Do not forget to build first, otherwise you will not find the dll.
The map control should appear in the Toolbox:
6) Add Map control to form
Now you are ready to write your first WPF app using GSuite and have a simple
functional map with a shapefile layer on top of OpenStreetMap. In addition, you will do
some simple spatial analysis on the shapefile.
So, let’s get started!
My first GSuite WPF Sample app
First, let’s look at some important concepts of mapping and GIS and how they relate to GSuite.
Important concepts
Data
In GIS, layers are the mechanism used to display geographic datasets in the map. Each
layer references a dataset and styles that determines how the data is going to be displayed and
labeled.
There are two major types of data in GIS, vector and raster.
Vector data type is a coordinate-based data model that represents geographic features
as point, lines and polygons.
-Point features are represented as a single coordinate pair.
-Line features are represented as ordered lists of vertices.
-Polygon features are represented as closed ordered lists of vertices.
Very often, attributes are associated with each vector feature.
Many formats exist for storing data in vector. The most popular are shapefiles, Tab files,
GeoJSON, KML. In this exercise, we will use a shapefile.
In GSuite, the most important class related to vector data type is BaseFeatureSource, the
abstract class from which all vector layers are based on for the data access and source. Also
important is BaseFeatureLayer, the abstract class from which all vector based layers are based
on for the styling and drawing logic. For example, ShapeFileFeatureLayer uses
ShapeFileFeatureSource for the access logic of the actual shapefile files (.shp, .shx, .dbf).
Raster data type is a spatial data model that defines space as an array of equally sized cells
arranged in rows and columns. Each cell contains an attribute value. Unlike the vector type
which stores coordinates explicitly, raster coordinates are contained in the ordering of the
row/column matrix. You can think of raster as image with a geographic dimension.
Many formats exist for storing data in raster. The most popular are GeoTIFF, JPEG2000,
GRID, ECW. Keep in mind that web map services such as Google Maps, Bing Maps, Here
Maps and OpenStreetMap are based on raster since they returns images. In this exercise,
we will use OpenStreetMap.
As for Vector, GSuite uses the classes BaseRasterSource and BaseRasterLayer in the
same logic.
So, you can see that there are two different types of layers. Vector layers such as shapefiles
that are based on the vector model and raster layers that are based on the raster model.
Note that many organizations use a relational database to store its spatial data. They are
called spatial databases and are used to store vast amount of data and to work in a multi-user
environment. Popular spatial databases are Microsoft SQL server spatial, PostGIS and
SpatiaLite.
The geospatial data formats
You can find more detailed info on vector, raster, web map services and spatial
databases in the guides:
- Data guide
- Web Mapping Services guide
- Spatial Databases guide
In those guides, you will find valuable information on those different formats and
especially on how to extent BaseFeatureSource with your own format if you need to.
LayerOverlay highlightOverlay = new LayerOverlay(); highlightOverlay.Layers.Add("Highlight", inMemoryLayer); WPFMap.Overlays.Add("HighlightOverlay", highlightOverlay);
Layers, Overlays and the Map
You can think of a LayerOverlay as a collection of layers. You add the LayerOverlays
to the Overlay collection of the map. It is recommended to create a LayerOverlay to
manage similar layers. For example, put all the static layers such as shapefiles in one
LayerOverlay and all the dynamic layers such as InMemoryFeatureLayers in another.
That way you can refresh one LayerOverlay without having to refresh the entire map.
There are also TrackInteractiveOverlay and EditInteractiveOverlay for doing shape
editing.
Next, we add the point with coordinates -25 of longitude and 2 of latitude (in the middle of the Atlantic) to the InMemoryFeatureLayer. That point on the map is used as the reference geometry to perform the distance query. Before doing the distance query, we have to do a projection conversion of the point to Spherical Mercator.
Always be aware of the map projection!
We have the coordinates of the point in longitude and latitude (WGS84) but the map is in
a different coordinate system (Spherical Mercator). So, it is necessary to perform a
projection conversion to that point so that it aligns well with the rest of the data.
Always be aware of that your data might not be in the same coordinate system!
Proj4Projection proj4Projection = new Proj4Projection();
//Geographic Coordinate System (WGS84) http://spatialreference.org/ref/epsg/4326/ proj4Projection.InternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
PointShape queryPointShape =(PointShape)proj4Projection.ConvertToExternalProjection(new PointShape(-25,2)); //25 degree west of longitude and 2 degree north of latitude
proj4Projection.Close();
The projection library
GSuite uses the library Proj4 for map projections and coordinates conversion. Virtually
all the projections in the world are supported from WGS84, Spherical Mercator, UTM,
Stateplane to the most obscure national projections.
You can find all the projections in spatialreference.org.
The geometric shapes Notice that a PointShape with X and Y coordinates was created. GSuite has geometry classes such as PointShape, LineShape, PolygonShape, RectangleShape etc to construct shapes. In addition, you can do various geometric operations and geometric operations on them. You can find more information in the Spatial Analysis Guide.
With the point now reprojected to match the base map (OpenStreetMap), we create a feature with that point. That feature is added to the InMemoryFeatureLayer.