Hot answers tagged

69

There are at least two good clustering methods for PostGIS: k-means (via kmeans-postgresql extension) or clustering geometries within a threshold distance (PostGIS 2.2) 1) k-means with kmeans-postgresql Installation: You need to have PostgreSQL 8.4 or greater on a POSIX host system (I wouldn't know where to start for MS Windows). If you have this ...


23

I've written function that calculates clusters of features based on distance between them and build convex hull over this features: CREATE OR REPLACE FUNCTION get_domains_n(lname varchar, geom varchar, gid varchar, radius numeric) RETURNS SETOF record AS $$ DECLARE lid_new integer; dmn_number integer := 1; outr record; innr ...


22

I see MerseyViking has recommended a quadtree. I was going to suggest the same thing and in order to explain it, here's the code and an example. The code is written in R but ought to port easily to, say, Python. The idea is remarkably simple: split the points approximately in half in the x-direction, then recursively split the two halves along the y-...


21

If you want a clusterer like redfin then check out my Leaflet.markercluster: https://github.com/Leaflet/Leaflet.markercluster/blob/master/example/marker-clustering-realworld.388.html https://github.com/danzel/Leaflet.markercluster It is fully animated etc etc :)


14

Here is a good tutorial for doing exactly that using MapBox and TileMill: A heatmap for all your runs in RunKeeper


14

I've done a bit of work on this in GeoTools/GeoServer by extending the Heatmap Rendering Transformation to support geometries other than points. It's not finished yet, but you can get the feature branch from my repository on GitHub. The screenshot is of GPS tracks from when I worked as a pizza delivery driver.


12

I've combined bits from several suggestions and added a bit of my own and found a solution which works well for me - and all from within QGis! I first ran a PostGis SELECT to find the points which have the right common attributes and lie within x km of each other: SELECT DISTINCT s1.postcode,s1.the_geom, s1.gid FROM broadband_data AS s1 JOIN ...


11

you can check out k-means clustering algorithm here. In data mining, k-means clustering is a method of cluster analysis which aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean. This results into a partitioning of the data space into Voronoi cells. kmeans-postgresql ...


10

In traditional cartography, marker clustering is called aggregation or sometimes amalgamation. It is part of model generalization: When zooming out, some detailed concepts (e.g. the tree) disappear to be replaced by less detailed aggregated forms (e.g. the forest). Many good examples can be found in good cartography books. Here are two examples from this ...


10

you have to use the union function like this SELECT att1, st_centroid(st_union(geom)) as geom FROM schema.table GROUP BY att1; so you can obtain centroid of point that have same attribute.


10

I've done some research. I took some points in two coordinate systems non metric (WGS84) and metric (Poland 1992). I used this code: from scipy import loadtxt from sklearn.cluster import Birch import matplotlib.pyplot as plt data84 = loadtxt("/home/damian/workspace/84.csv", delimiter=",") data90 = loadtxt("/home/damian/workspace/90.csv", delimiter=",") ...


9

So far, the most promising I found is this extension for K-means clustering as a window function: http://pgxn.org/dist/kmeans/ However I haven't been able to install it successfully yet. Otherwise, for basic grid clustering, you could use SnapToGrid. SELECT array_agg(id) AS ids, COUNT( position ) AS count, ST_AsText( ST_Centroid(ST_Collect( ...


8

It sounds like you need a clustering algorithm (eg. K-means clustering) first, followed by a hull (convex hull, but a concave hull may have a smaller area but more difficult to implement).


8

You can use Vector > Analysis Tools > Distance Matrix, and a join to achieve what you ask. I will use qgis sample data airport's layer to exemplify. This is a small dataset so I'm not sure how it will go with a 275000 points shapefile. 1. Create a distance matrix using your layer as both destination and target. Don't forget to tick "Use only the nearest (...


7

Try using the Buffer tool to buffer the points to a tolerance, dissolve to create single polygons for each cluster, and then use a join to count the number of points in the cluster. Then use the ratio between the area of the cluster and the number of points to apply your parameters.


7

None of the out-of-the-box tools in ArcGIS (or any other GIS, AFAIK) will do the job correctly. In a problem like this you need to quantify what you mean by "clustering" and then you need to posit a probability model to assess whether the measured degree of clustering could have been produced by accidental chances. As an example of how to proceed, you ...


7

Although not QGIS solution I'd personally opt for some exploratory analysis using SaTScan. It's fast, well documented and widely applied, so you shouldn't have troubles with starting up. 45k points might require some RAM though. I'm not sure if it can read directly from Postgres but easily imports from dbf and text files. The output of analysis can be then ...


7

There's a lot of options and in fact I struggled through the same question a while back on some of my applications. And for our different products we ended up with different solutions. So you have to ask yourself Are all of the singleton icons on the map of the same "kind" - same shape and color? If they're not, do they all live on 1 layer, or multiple ...


7

This may not be the most elegant solution, but, with some fine-tuning of the timeout durations and customization of the cluster icons, I think you can get the effect you are looking for. See this example. The trick is to first create a marker and set the map attribute in the marker options object. This adds the marker to the map with the nice drop ...


7

There are functions for computing true distances on a spherical earth in R, so maybe you can use those and call the clustering functions with a distance matrix instead of coordinates. I can never remember the names or relevant packages though. See the R-spatial Task View for clues. The other option is to transform your points to a reference system so that ...


7

You do not have a uniform random field, so attempting to analyze all of your data at once will violate the assumptions of any statistic you choose to throw at the problem. It is unclear from your post if your data is a marked point process (i.e, diameter or height associated with each tree location). If this data is not representing a marked point process I ...


7

The Concave Hull plugin adds Shared Nearest Neighbor Clustering to processing


6

OpenLayers has also a cluster strategy. All you need to do is to specify as strategy in the vector layer. The solution is very "simple" for the moment, simply reduces the number of points depending on the zoom level. If you need something more awesome you will need to program it by yourself and your needs. Take a look also to SelectFeature control which ...


6

See if this algorithm gives enough anonymity for your data sample: start with a regular grid if polygon has less than threshold, merge with neighbor alternating (E, S, W, N) spiraling clockwise. if polygon has less than threshold, go to 2, else go to next polygon For example, if the minimum threshold is 3:


6

One quick and dirty way uses a recursive spherical subdivision. Beginning with a triangulation of the earth's surface, recursively split each triangle from a vertex across to the middle of its longest side. (Ideally you will split the triangle into two equal-diameter parts or equal-area parts, but because those involve some fiddly calculation, I just split ...


6

You need to do this in a two-stage process using the Vector->Analysis Tools->Mean Coordinates tool in the second step. This tool will return the mean coordinates for sets of point within a layer if they have a unique ID field. So, if you have a polygon layer which defines your areas, do a spatial join (Vector->Data Management->Join attributes ...


6

Previously I'd written a hierarchical clustering algorithm that operated on small groups of points, but it did not scale well to an 8000 point cloud. After some tinkering I got a revamped version to work. It does 8000 points in under 30s on a server, scaling at something approximating N*log(N). First two tables definitions are required: CREATE TABLE pt ( ...


6

If you can updgrade to postgis 2.2.0 you might be lucky because that feature has just been introduced. From the doc: "ST_ClusterWithin is an aggregate function that returns an array of GeometryCollections, where each GeometryCollection represents a set of geometries separated by no more than the specified distance." Check this: http://postgis.net/docs/...


5

A fairly simple way is to snap the events to a grid. It's fast enough that potentially you can do it dynamically. You can snap the points by means of a few simple computations before creating the events. Decide on the grid's origin and mesh size, using the same coordinate system as the (X, Y) values you have. Let the origin have coordinates (Ox, Oy) and ...


5

Follow-up with some other non-commercial web apps people have been developing: Florida is rolling their own MyDistrictBuilder web ap: http://www.floridaredistricting.org/ (app may be at http://floridaredistricting.cloudapp.net/MyDistrictBuilder.aspx, website claims they'll have public testing in March) Profs. Altman and McDonald are developing the open-...



Only top voted, non community-wiki answers of a minimum length are eligible