Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Geo-Referenced Images in C#

I want to create some heat-map style tiles to overlay over our base maps using Open Layers. Basically, I want to divide some some bounding box into a grid, and display each square of the grid using a different color based on how many points of a sample fall within that grid square.

The technologies involved are C#, OpenLayers, SQL Server 2008 and GeoServer.

My question is basically one of general approach, I'm not really sure where to put the tip of the chisel on this one.

My ultimate goal is to be able to take any arbitrary bounding box, calculate an x-mile by x-mile grid that fits within that bounding box, the iterate over a collection of individual points and assign them to one grid square or another so I can calculate point density per grid square, then color the grid according to the densities, then overlay that on a CloudMade base map using Open Layers.

Any help at all would be greatly appreciated, on the whole thing or any piece of it.

like image 325
Nathan Avatar asked Oct 14 '25 16:10

Nathan


2 Answers

If your bounding box is axis aligned, this is fairly simple. Just make your image, and create a world file for it by hand. The world file is just 6 lines of text, and you already know everything needed (x & y pixel size, coordinate of your upper left corner).

Just make sure that you use the CENTER of the upper left corner pixel, not the corner of the box.

------ Here's how you'd make the world file -------

Say your bounding box's upper left corner is at 203732x598374, and you want an image that has rectangles that are 200m wide east<->west and 300m tall north<->south.

You'd make an image that was the appropriate number of pixels, then a world file that had the following 6 lines:

200
0
0
-300
203632
598524

This corresponds to:

200 == size of one pixel in X
0 == shear1
0 == shear2
-300 == size of one pixel in Y (from top down)
203632 == left edge - 1/2 pixel size (to center on pixel instead of edge of box)
598524 == top edge - 1/2 pixel size (to center on pixel instead of edge of box)

If you use a .png image, you'll want to save this with the same name, but as .pgw. If you use a .jpg, it'd be .jgw, etc.

For complete details, see: Wiki on World Files

like image 101
Reed Copsey Avatar answered Oct 17 '25 05:10

Reed Copsey


"Dividing some some bounding box into a grid, and displaying each square of the grid using a different color based on how many points of a sample fall within that grid square." This is a raster and there are features in GeoServer for displaying these with colour shading, legends and so on. I think it will be more flexible to use these features than to create image tiles in C#.

From the GeoServer documentation:

Raster data is not merely a picture, rather it can be thought of as a grid of georeferenced information, much like a graphic is a grid of visual information (with combination of reds, greens, and blues). Unlike graphics, which only contain visual data, each point/pixel in a raster grid can have lots of different attributes, with possibly none of them having an inherently visual component.

This is also called thematic mapping or contour plots or heatmaps or 2.5D plots in other GIS packages.

You could use a free GIS like Grass to create the raster grids, but from your description you don't need to interpolate (because every cell contains at least one point) so it might be just as easy to roll your own code.

EDIT: there is an open source library GDAL which you can use to write raster files in various formats. There are C# bindings.

like image 41
MarkJ Avatar answered Oct 17 '25 04:10

MarkJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!