Visar inlägg med etikett Spatial Math. Visa alla inlägg
Visar inlägg med etikett Spatial Math. Visa alla inlägg

måndag 22 januari 2018

Spatial Server Tools?

Over time Microsoft has a history of developing mapping services and applications. It spans from Encarta, with map tours, to lately announced Location based services on Azure. MSFT took the path through various online services such as MapPoint, Virtual Earth and Bing Maps.

I believe over time Microsoft have developed suite tools for handling GIS and spatial information (otherwise they would not deliver the services they have). One thing I found a bit odd is the current Bing Maps client is really powerful with the Spatial Math library in combination with services and the new routing API. But there are not so many tools on the server. Of course there is SQL Server and the library Microsoft.SqlServer.Types. Developing server side GIS with .Net you will probably end up with ESRI or NetTopology Suite (NTS), a powerful open source library).

But I believe there is room and a need for yet another library. For example:
  • Test geometry generator, create test geometries
  • IO, various formats.
  • Spatial Math
  • Geometry compression
Above are all low hanging fruit. In fact all of them are in Bing Maps client.

What if just the functions in Bing Maps client would also be available server side? That would include all four points above. Or what if just the Spatial Math library would be available as a NPM package? Or even a Nuget package and expand from that? 

torsdag 18 januari 2018

Drawing a donut in Bing Maps


Background

Polygons with holes aka donuts have been a challange in web mapping. For not too long ago when customers asked if it is possible to have holes in polygons, I was avoiding the question. It is possible to send an array of rings to the polygon constructor. But within Spatial math library it is possible to achieve holes in polygons pretty easy. If a user draw a polygon on top of a polygon on the same layer, it might mean a hole.

Steps

  1. Create a polygon. The easiest way I know for this use case is to make a circle. 
  2. Create another smaller polygon, a polygon that I use to punch out the hole on the bigger polygon.
  3. Use the difference function in Spatial Math library to punch out the polygon.
  4. Add the donut polygon to the map. Done. 

Implementation

Assuming there is an instantiated Bing Maps variable named map...
 Microsoft.Maps.loadModule('Microsoft.Maps.SpatialMath', () =>; {
    const outer = Microsoft.Maps.SpatialMath.getRegularPolygon(map.getCenter(),
                  30, 36, Microsoft.Maps.SpatialMath.DistanceUnits.Kilometers);

    const outerRing = new Microsoft.Maps.Polygon(outer);


    const  inner = Microsoft.Maps.SpatialMath.getRegularPolygon(map.getCenter(), 
                   10, 36, Microsoft.Maps.SpatialMath.DistanceUnits.Kilometers);

    const innerRing = new Microsoft.Maps.Polygon(inner);
        
    const donut = Microsoft.Maps.SpatialMath.Geometry.difference(outerRing, 
                  innerRing);

    map.entities.push(donut);

    });
It is surprisingly easy to accomplish holes in polygons - and drawing circles. It is about ten lines of code depending on how you count it. Inside the module, it is in fact six lines that acctually do something.

It is powerful, easy to use and it solves reall world problems, like drawing islands on a lake. Or lakes on islands. 

måndag 7 augusti 2017

How far can my electric car take me?

Routing- and module pearls in Bing Maps

Bing maps v8 has been released quite some time now. At a first glance, the API offering what to expect. There are a few things that I would like to have seen as part of the core API.  For example, GeoJSON as it is more or less the industry standard transferring GIS data over network.  However, the sweet juicy bits are in modules and are available whenever needed. Be aware it is not JavaScript modules. The modules spans from visualization, parsing, digitizing to analyze. Some modules, such as GeoJSON, might over time be part of the core API. Adding GeoJSON parsing would indeed make sense. For a complete list of modules see https://msdn.microsoft.com/en-us/library/mt712663.aspx.

Microsoft.Maps.SpatialMath is a truly competent module. That module adds complex spatial calculations and analysis. And yet there is more, combining this module with projects like Nanjing opens up for interesting applications.  For example, how far can I get with my electric car? Or, consider truck drivers, at least in Sweden, they are allowed to drive for a limit of time without having a break. Let’s say 2 hours, then they need to have a break for 15 minutes or so, then they can continue. I don’t know the exact limits. The industry definitely has a need to plan the route with stops accordingly to regulations. For example they might need to find a stop along the route between 90-120 minutes.

To resolve the use case above one way could be:

  1. Calculate the route from A to B.
  2. Calculate Isochrones from start to 120 minutes.
  3. Calculate Isochrones from start to 90 minutes.
  4. Use Microsoft.Maps.SpatialMath.difference operation to resolve the area between 90-120 minutes.
  5. Buffer the area, Microsoft.Maps.SpatialMath.buffer
  6. Use the buffered area and Microsoft.Maps.SpatialMath.intersection operation to calculate the route that is between 90-120 minutes (intersection)
  7. Visualize the calculated (intersected) area.

In these steps, a pretty complex problem has been addressed. From the routing-service I got the isochrones, then it is easy to combine the isochrones with geometry math operations. The operations I used is:
  • Intersection (to see where the buffer overlaps the difference area.
  • Buffer (for better visualization of the located area)
  • Difference (between the isochrones)


Now it is easy to find a spot where the driver must find a place to stop. Remember, from the beginning this is not a trivial problem, by combining powerful geodataservices, client-side operations and knowing how to solve the pieces in the puzzle makes it is easy to finish.

I made a demo application to this post. https://github.com/perfahlen/BingMaps-Routing-And-Module-Pearls