Problem overlaying Shapes on Tiled ( Bing Maps/Yahoo Maps etc)

May 29, 2013 at 10:25 AM
Hi All,

I tried to overlay my polygon layer stored in Sqlserver 2008 spatial along with bingmaps.
But some how the image created using my data does not overlay properly on the bing map tiles. ( its way too small and no image for bingmap is available for that resolution)

I am sure its a problem related to projection system problem. It would be very helpful if some one could help me solve this problem and also answer my queries below.
  1. I am using shapefiles projection: WGS84 ( what projection should i reproject these files before I import them to the SQLServer.
  2. I am using Shape2Sql exe to import the data into Sqlserver. Can anyone specify if there are any specific parameters I need to set while importing the data into the SQLServer.
Thanks in advance
Arun
Editor
May 29, 2013 at 10:44 AM
Its probably a projection issue as you assumed.

Generally web based maps are projected using the 900913 projection, Which is a global grid system with units of meters, so as you can imagine the coordinates are quite large. Typically if you overlay as WGS84 geometry (with coordinates like -1.898, 52.456) over a map with this projection they will be plotted close to the equator near the prime meridian!

So you need to convert your data to 900913 (Web Mercator) projection. You can either do this as a one off using a tool like Qgis, then import the reprojected data into sqlserver. Or you can do it on the fly in SQL using the ST_Transform function to convert, or you can do it on load in sharpmap using the Proj4 functions.

If you just need to do it as a one off then do it in QGis.
May 30, 2013 at 6:01 AM
Robert

Thanks for the info ill try this and let you know :).

Regards,
Arun
May 30, 2013 at 7:24 AM
Hi Robert,

I did the changes and I am getting the image over my tiles but somehow the performance is hampered big time.
Have you faced this issue or is there any settings that I need to do get the same speed as earlier ?
Do you have any suggestions to improve the performance ?

Regards
Arun
Editor
May 30, 2013 at 7:37 AM
How is the performance suffering?

If the polygons cover a large area, and you have a full screen map, you will probably see a delay in the tiles being rendered as you are pulling them from the server. To tackle this you'll need to set up a local cache that store the map tiles locally, although I think this might infringe the bing maps copyright.

The polygons should draw quite fast though. Make sure you have the shapefile indexed. I also believe there is an option in the shapefileprovider to specify using in memory index. This will improve performance for small to medium shapefiles.

If you say how the performance is different then we might be able to help more.
May 30, 2013 at 7:55 AM
Hi Robert

The map takes time to load on to the control and then also while zooming and out it takes time to load as compared to the maps when generated using the tables where I have data in wgs 84 projection system , those are really fast.

I tried both with/without the base map tiles from bing but the performance as mentioned above was slower.

I will try the indexing option and let you know.

Regards
Arun
May 30, 2013 at 9:40 AM
Hi Robert

Here are the steps that I took to plot the shapefile on the maps.
  1. Converted the shapefile to Web Mercator in ArcGIS
  2. Added attribute as well as spatial index in ArcGIS
  3. Imported the file to SqlServer 2008 using Shape2Sql
  4. Enabled Spatial indexing during the import and specified the SRID as 900913 (Also checked the spatial index on the column).
  5. Used this table to create the map.
Code change
layCountries.SRID = 900913;

But the performance is still not improved.

Even if I dont use the background tiles from bing the rendering is far slower than
when compared to the tables that I create using the WGS84 Projection.

I tried the same table even in the SqlSpatial.exe

The loading of the shapes (with table having Web Mercator) are slower there too when compared to those tables which were created using wgs84 projection system.

Hope you can help me out with this issue.

Regards
Arun
Editor
May 30, 2013 at 10:27 AM
How complex are the polygons?

Are you storing them as geometries or geographies?

If you run a select query in sql on both versions of the table are the results slower for the 900913 layer?

can you set a break point in your code to see where the bottle neck is?

There might be some bounding box transform now that you didn't have before so make sure the map is also set to use 900913
Coordinator
May 31, 2013 at 7:16 AM
Arun, the things that affect performance on rendering
  • Theming, as this requires gathering of data
  • the use of a FilterDelegate (in case of ShapeFile provider)
  • setting of a CoordinateTransformation for on-the-fly reprojections.
  • the effects resulting from different Pen styles (Width, DashStyle ...)
Now, to see what your issue might be, please show us your map setup code.
FObermaier
Jun 1, 2013 at 9:25 AM
Robert,

Thanks for pointing out about the geometries. I found out the problem.
It was not because of the projections it was due to the number of shapes that made a unique feature.

Earlier table ( the one with WGS84 ) had geometries created from shapefiles which were corrected for combining geometries having similar ID's.
While the later had many number of polygons with same ID's resulting large number of polygons.

I tried it with the combined one and it works fine now.

Thank you and FObermaier for your prompt help and directions really appreciate it helped me a lot.

Regards,
Arun