I did have a method called density at some stage, it got renamed before the
code went into beta. The density like generalisations are now available using:
regionUnivariateStatistics (
Grid2DSquareCellDouble grid,
Vector statistics,
double distance,
double weightIntersect,
double weightFactor,
Grid2DSquareCellDoubleFactory gridFactory )
grid is the input raster in a 2D square celled form
statistics contains strings for controlling which statistics to generate
distance gives the radius of the kernel
weightIntersect gives the weight at the kernel centre
weightFactor controls the change in weight over the radius
gridFactory is a factory for creating the outputs
The statistics that can be generated are as follows where W stands for weighted
(using the kernel), N stands for normalised (this is important when there are
no data values for some cells):
Sum
WSum
NWSum
WSumN
Mean
WMean1
WMean2
NWMean
WMeanN
Prop
WProp
Var
WVar
Skew
WSkew
CVar
WCVar
CSkew
WCSkew
SDWMean
SDWMeanPow2
SDWMeanPow3
SDWMeanPow4
SDWMeanPow2 is a form of moment - the Sum of the Difference of the Weighted
Mean Squared. The statistics names could do with more explanation... Indeed,
the code could be better documented and I'd like to refactor it as it now seems
so old and ugly... Anyway, I believe it should still work and could be useful...
Some details of the kernel I implemented are in the following draft paper which
for some reason I gave up writing years ago:
http://www.geog.leeds.ac.uk/people/a.turner/publications/papers/working/RasterBasedGWS_0.2.doc
In the paper, search for the word "kernel" and there is an equation and a
picture of the distance weighting (with different shapes for different
parameters). It looks sort of Gaussian shaped for some parameter values, the
general shape is monotonic. I should be fairly straightforward to implement
some other kernel weighting...
I've just built the grids code afresh. There are two dependencies, a generic
library of mine and GNU Trove version 2.x
(http://sourceforge.net/projects/trove4j/files/trove/2.1.0/trove-2.1.0.tar.gz/download).
I just refactored so that JAI is optional and can be sort of plugged in. (JAI
was used as an optional way of storing the data, it was not the best data store
and the way I've refactored means it is easily pluggable if wanted and there is
no longer any need to have it unless plugging in those classes on which it
depends.
I've checked in the latest grids into the following svn:
https://e-research.cs.st-andrews.ac.uk/repos/sim/grids/
You can check out the whole thing using:
svn co https://e-research.cs.st-andrews.ac.uk/repos/sim/grids/
I have further Java for Geographically Weighted Statistics that inputs X, Y
coordinate point data.... This passed the kernel over this for the same grid
like raster and generalises the points and their values rather than the values
of the grid cells. I think that really this is what you want. This has methods
for fixed radius and adaptive bandwidths - the adaptive bandwidth is the one
that encompasses a specific number of points.
I hope this has not scared you off and you are still interested.
Cheers,
Andy
________________________________
From: Peter Borissow [[email protected]]
Sent: 22 November 2011 18:32
To: Andy Turner; Michael Bedward
Cc: geotools-gt2-users
Subject: Re: [Geotools-gt2-users] Kernel Density Estimation - KDE
Thanks Andy-
GWS, Slope, Aspect - a lot of good stuff in there! Which class is used to
create a density surface? I must have missed it at first glance.
Also, does your density calculation use a Gaussian kernel similar to the one
used in spatial analyst?
http://www.quantdec.com/SYSEN597/GTKAV/section9/density.htm
Thanks,
Peter
________________________________
From: Andy Turner <[email protected]>
To: 'Peter Borissow' <[email protected]>; Michael Bedward
<[email protected]>
Cc: geotools-gt2-users <[email protected]>
Sent: Tuesday, November 22, 2011 12:41 PM
Subject: RE: [Geotools-gt2-users] Kernel Density Estimation - KDE
Hi Peter, Michael, geotools-gt2-users,
I developed some Java for creating density surfaces (and other statistics). It
was based on the original GeoTools Raster class and has the LGPL license. Sorry
I did not managed to re-integrate my work back into GeoTools.
The main web page for my efforts which I called Grids can be found via the
following URL:
http://www.geog.leeds.ac.uk/people/a.turner/src/andyt/java/grids/
One of the example uses of Grids was to produce different statistics (output as
rasters) based on the generalisation of point data. These statistics could be
distance weighted and draw in values across a range of scales. Essentially it
worked with distance weighting. There were statistics based on a single set or
values of points and others based on two sets or values of points. I didn’t get
any further than that.
I am happy to revisit my code, adapt an example to use your data and release a
new version if you want.
Andy
http://www.geog.leeds.ac.uk/people/a.turner/
From: Peter Borissow [mailto:[email protected]]
Sent: 22 November 2011 12:45
To: Michael Bedward
Cc: geotools-gt2-users
Subject: Re: [Geotools-gt2-users] Kernel Density Estimation - KDE
Hello Michael-
Thanks for your response. I *think* the way to go is to start off with a
raster surface (GridCoverage2D) and iterate through all the pixels in the grid
and measure distances to all the neighboring points (points that fall within a
certain distance of the pixel). Knowing relative distances to the neighboring
points, we can apply a simple calculation to assign a weight to the given pixel.
Can you please point me to an example of how to iterate through all the pixels
in an empty GridCoverage2D, get the coordinate for that pixel, and assign a
value for the pixel?
Many Thanks,
Peter
________________________________
From: Michael Bedward <[email protected]>
To: Peter Borissow <[email protected]>
Cc: Georges Tony <[email protected]>; geotools-gt2-users
<[email protected]>
Sent: Tuesday, November 22, 2011 3:47 AM
Subject: Re: [Geotools-gt2-users] Kernel Density Estimation - KDE
Hello Peter,
> That's right. I want to pass in a collection of points and radius and get
> back a raster image (GridCoverage2D). I envision something as simple as
> this:
>
> public GridCoverage2D getDensityMap(java.util.ArrayList<Point> points,
> double radius, String units){
> }
Ah yes, simple is beautiful.
> Does something like that exist in GeoTools today?
No. At least, not yet.
One way to do it would be to first rasterize your point features and
then run a convolution over the resulting grid coverage. For the first
the step you can use the VectorToRasterProcess class and its static
process method. You'll find this is in the unsupported gt-process
module in GeoTools version 2.7.x or the gt-process-raster module in
GeoTools 8.x (because the module is unsupported it is not in the
online javadocs). For the second step there is a Convolve operation
which takes a kernel and applies it to a grid coverage:
http://docs.geotools.org/latest/javadocs/org/geotools/coverage/processing/operation/Convolve.html
There are some gotchas with the above method. The first is that the
rasterizing process expects a numeric feature attribute to use for
corresponding raster values. If you want to generate a heat map based
on point frequency within a neighbourhood, which I assume you do, you
will need an attribute with the value 1 for all features.
Alternatively you could hack the process code. A second, more serious
complication is that if multiple points fall into a single grid cell
only the last one processed contributes to the raster value. Depending
on the nature of your data, it may be possible to avoid this by
specifying a sufficiently fine grid resolution when rasterizing so
long as that doesn't result in blowing out your system's memory. Once
again, you could hack the process code to get around this.
Personally, I'd cheat and create a raster image from the feature data
"by hand" where cell values are point frequency; convolve the raster
using JAI or JAITools to create the density image; and finally turn
that into a GridCoverage2D. If you want to try that, let me know and
I'll rustle up some example code. Meanwhile, others here might have
better, simpler, more elegant suggestions.
Michael
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users