[mapserver-users] Heatmap / choropleth from points attributes
Tamas Szekeres
szekerest at gmail.com
Wed Feb 23 02:01:36 PST 2011
Daniel,
Not sure if that fully satisfy with your requirements but I've already done
a similar task with the following steps:
1. Create a point data source (with attributes) from your points for example
by using ogr_vrt <http://www.gdal.org/ogr/drv_vrt.html>, something like:
<OGRVRTDataSource>
<OGRVRTLayer name="mypoints">
<SrcDataSource>ponts.csv</SrcDataSource>
<GeometryType>wkbPoint25D</GeometryType>
<GeometryField encoding="PointFromColumns" useSpatialSubquery="TRUE"
x="lon83" y="lat83" z="attribute"/>
</OGRVRTLayer>
</OGRVRTDataSource>
2. Use gdal_grid <http://www.gdal.org/gdal_grid.html>to create an
interpolated grayscale image from the point data dource.
3. To colorize the raster create (or compute) a LUT for each color band by
containing the following information:
<LUT>[src value 1]:[dest value 1],[src value 2]:[dest value 2],...</LUT>
A template of this vrt should look like this:
<VRTDataset rasterXSize="{RASTERXSIZE}" rasterYSize="{RASTERYSIZE}">
<VRTRasterBand dataType="Byte" band="1">
<ColorInterp>Red</ColorInterp>
<ComplexSource>
<LUT>{LUT_RED}</LUT>
<SourceFilename>{SOURCEFILE}</SourceFilename>
<SourceBand>1</SourceBand>
<SrcRect xOff="{SRCXOFFSET}" yOff="{SRCYOFFSET}" xSize="{SRCXSIZE}"
ySize="{SRCYSIZE}"/>
<DstRect xOff="0" yOff="0" xSize="{RASTERXSIZE}"
ySize="{RASTERYSIZE}"/>
</ComplexSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="2">
<ColorInterp>Green</ColorInterp>
<ComplexSource>
<LUT>{LUT_GREEN}</LUT>
<SourceFilename>{SOURCEFILE}</SourceFilename>
<SourceBand>1</SourceBand>
<SrcRect xOff="{SRCXOFFSET}" yOff="{SRCYOFFSET}" xSize="{SRCXSIZE}"
ySize="{SRCYSIZE}"/>
<DstRect xOff="0" yOff="0" xSize="{RASTERXSIZE}"
ySize="{RASTERYSIZE}"/>
</ComplexSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="3">
<ColorInterp>Blue</ColorInterp>
<ComplexSource>
<LUT>{LUT_BLUE}</LUT>
<SourceFilename>{SOURCEFILE}</SourceFilename>
<SourceBand>1</SourceBand>
<SrcRect xOff="{SRCXOFFSET}" yOff="{SRCYOFFSET}" xSize="{SRCXSIZE}"
ySize="{SRCYSIZE}"/>
<DstRect xOff="0" yOff="0" xSize="{RASTERXSIZE}"
ySize="{RASTERYSIZE}"/>
</ComplexSource>
</VRTRasterBand>
<VRTRasterBand dataType="Byte" band="3">
<ColorInterp>Alpha</ColorInterp>
<ComplexSource>
<LUT>{LUT_ALPHA}</LUT>
<SourceFilename>{SOURCEFILE}</SourceFilename>
<SourceBand>1</SourceBand>
<SrcRect xOff="{SRCXOFFSET}" yOff="{SRCYOFFSET}" xSize="{SRCXSIZE}"
ySize="{SRCYSIZE}"/>
<DstRect xOff="0" yOff="0" xSize="{RASTERXSIZE}"
ySize="{RASTERYSIZE}"/>
</ComplexSource>
</VRTRasterBand>
</VRTDataset>
4. Use the gdal vrt <http://www.gdal.org/gdal_vrttut.html> driver (and
gdal_translate <http://www.gdal.org/gdal_translate.html>) to create the
final image (see an example attached).
Best regards,
Tamas
2011/2/23 Daniel Cole <daniel at southernsolutionsms.com>
> I am a new mapserver user and have spent countless hours over the last
> month reading, trying code, etc. before posting here for help. I am trying
> to generate an image (non-interactive) on a webpage based off of attribute
> data in a points file. For example, 20 different points equally distributed
> in a field contain data about the moister level of the soil. I want to make
> the lowest levels blue and the highest levels yellow, or something like that
> with some gradients in between. If possible I want it to have interpolated
> data between them to show the gradual change, but that isn't a must. I
> also want to wrap it in a polygon that trims the edges.
>
> I found some python code that I thought might do the trick , but it seems
> lots of heat maps are based off of how many points exist in a certain area,
> and thats now what I am doing.
>
> My points contain numbers in the attributes, 5, 25, 92, 71, etc. I feel
> like I am missing some easy way to do this right in front of me with gdal or
> something. If someone has any direction or even demo code that would be
> greatly appreciated.
>
> Thanks,
>
> Daniel
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110223/22b171b9/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tile.png
Type: image/png
Size: 145497 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20110223/22b171b9/attachment.png>
More information about the MapServer-users
mailing list