I'd suggest to use the ST_ClusterDBSCAN Window function rather than the Aggregate function ST_ClusterWithin:
ST_ClusterDBSCAN(the_geom, eps := <distance>, minpoints := 1) OVER() AS clst_id
clst_id will hold INT values representing the cluster each rows geometry belongs to.
As stated in the comments, ...
ST_ClusterWithin is an aggregator function, meaning it will not generate a new geometry, but simply output the geometries that were input to it, albeit in a particular grouping (the clusters, in this case).
If you want a visual representation of your clusters, you can do so by feeding your resulting Geometry Collections into ST_ConvexHull. This will give ...
If you prefer to address this issue in "the raster logic", then there are a few filters that you could consider. The best choice will depend on the spatial distribution of your pixels of each class inside your "background" values, but here are two potential solutions :
if your patches that you want to remove are relatively large, then you should use "sieve" ...
You can do this. First, create the column in your table.
ALTER TABLE point
ADD COLUMN cid integer;
Then update your table based on your query. When you do your DBScan query. Make sure you select an id field that can be matched back to the points.
SET cid = subquery.cid
FROM (SELECT id, st_clusterdbscan(geom, eps := 0.01, minPoints := 5) over() as cid
Interesting, haven't seen the Fréchet distance before (it seems to be the equivalent of Hausdorff distance, but for lines rather than polygons)
It looks as if there may be an implementation in the MDAnalysis library.
However, this library appears to be for analysing movements of molecules ... it's python built on numpy, but is not designed for geospatial.
The buffer-intersection construct in general is better be avoided in favor of the (for some reason not always index driven, but still) more efficient ST_DWithin. However, you will still need to implement a table self-join, and that will imply unnecessary overhead in this case.
I suggest to look into ST_ClusterDBSCAN instead; note that this will only work if ...
In terms of a local autocorrelation (nonstationarity) statistics, there really is not one. Join-counts is adequate for hypothesis testing of global clustering in binary process, albeit very scale dependent, but not for multinomial data. I am not even sure what the underlying hypothesis test would be here, especially with ordinal data. One has to ask, how ...
I have been able to work around the limitation by "pre-computing" the values for eps and inferring reasonable values of the other subqueries which where previously referring to the recursive CTE.
Note that the new solution may create clusters larger than wanted (5000 in the query below) if you run-out of "pre-computed" values. This helps ensure that the ...
20000 is most probably in degrees - which is why all of your geometries are in cluster 0 (if it was failing to cluster they would be in NULL). You need to convert your data to be in metres by reprojecting into a local projection (SRID). For example EPSG:5243 would work, so something like:
ALTER TABLE table ADD COLUMN geom_m GEOMETRY;
UPDATE table SET geom_m ...
Just a technicality
(should be a comment but I lack reputation):
In any case this needs a coordinate reference system that gives you euclidean distances in your attribute space, for example UTM:
# specify original CRS:
proj4string(house) <- CRS("+proj=longlat +datum=WGS84")
# transform to new CRS (need to specify correct UTM zone):
You get an entry for each voter because you are grouping on the voter column as well, which results in groups that are all single rows. And you cannot include voter_name in the query unless you either aggregate on the column or build groups that include the column, which means that you have to add one more query level to achieve your objective.
Here are a ...
Given you already have your RED 6km span points which I am referring to red_points, you can do something like this to obtain your 3X3 200m grey_points.
(please, adjust the sign (+/-) as you wish to achieve your result. Also, here 200 is in meters as long as the units of your reference system is meter.)
red_points = "your_red_points_fc_here"
You really want to use the mighty ST_ClusterDBSCAN:
ST_ClusterDBSCAN(geom, 0, 1) OVER() AS clst_id
where clst_id is an integer value representing the cluster a row (geometry) belongs to.
With a eps distance of 0, the function effectively clusters by intersection only.
It's unclear to me what you are trying to do here, but if you need to do an unnest, you are better off using ST_ClusterDBScan if you have PostGIS 2.3+.
I'm also not clear why you have two calls to ST_ClusterWithin each with different distance.
WITH c AS (SELECT ST_ClusterDBScan(centroid,100,10) AS cluster_num, ...
I've done something similar to this hundreds of times. You didn't provide enough information to provide more than a stick-figure solution, but one way to do it would look like this:
UPDATE mytable t
SET colval = vt.colval
FROM mytable t
JOIN othertab j ON j.geomcol && t.geomcol AND
My interpretation of your question is that you are not simply trying to set a zoom level on an interactive map, and your point groups near each other do not share a common attribute. If my understanding of your question is incorrect, please modify your question to provide more details, as you will get a different answer.
Based on my two assumptions, and ...
No time for more improving or testing, but: for a single, more generic recursive term, and possibly better performance, try
params AS ( -- convenience variables for testing parameters
SELECT 10 AS max_size, -- max. cluster size
1 AS min_points, -- 'min_points' parameter
ST_GeometricMedian should compensate for outliers in MultiPoint geometries, e.g. sth. like:
SELECT ST_GeometricMedian(ST_Collect(geom)) AS geom
General info on the concept, and difference to weighting (i.e. ST_Centroid).
As an alternative, using
ST_ClusterDBSCAN(geom, <eps>, 1) OVER(PARTITION BY ...
Let's work through a Haussdorf clustering of lines.
We'll use the sf package for spatial data and distance calculations:
starting with your final x, lets group everything by cyclone number, make line features, and keep the number of points in the group:
cyclones = x %>% group_by(CycloneNo) %>% mutate(n=n()) %>% summarize(n=mean(n),...
Vast question, a matrix distance is really not the way to go for a lot of points. If you want to do it yourself, look into quadtree and nearest neighbourg. The classicals algorithms used for clustering would be DBScan or Kmeans, but for your exemple you can simply use Postgis and the function ST_ClusterWithin (and you can test ST_ClusterDBSCAN and ...
Not the best solution in your related post. Use focal statistics (maximum) for neigbourhood of your choice, e.g. 500*500 cells, output - raster, called FC.
Use raster calculator to locate highest points:
Convert output raster to points, e.g.:
Use ST_ClusterDBSCAN (follow the provided links for further details on the algorithm and the impact of the function arguments); as a Window function, it operates on the input rows within a defined frame, where it assigns cluster ids as column values:
SELECT ARRAY_AGG("ID_1") AS "ID_1's",
ARRAY_AGG("ID_2") AS "ID_2'...
Actually, the cluster renderer does support categorized styles.
Next to the word Renderer there's a dropdown menu, where you can choose Categorized.
Under the Renderer type selection menu, click the button Rendering Settings... to access the normal layer style panel settings for a Categorized style.
Categorize by the field that has values. Un-check the ...
The eps distance is the maximum distance between points in the cluster, not the maximum width of the entire cluster.
So if you have points A, B, and C, as long as each point is within the eps distance of one other point, then it gets included in the cluster. If the eps distance was 1 km, A could be within 1 km of B, and C can be within 1 km of B, but A can ...
Maybe you can try an iterative approach:
You first use ST_ClusterDBSCAN with a big eps and a small minpoints, and then you isolate the points that are in a cluster too big for you, for exemple using the radius of the bounding circle (general idea, not tested):
sqrt(ST_Area(ST_MinimumBoundingCircle(ST_Collect(points)))/pi) > your_threshold group by ...
Seems like the correct name of the function is
In general, when you get an error: " 'module' object has no attribute X", it means that there is no function named X in the library/module/class, which means you probably have written something wrong in the name of the function, which should be quick to ...
Not a full-fledged answer, but:
Build an adjacency matrix of your polygons, to know which is adjacent to which. This may be done either through the R provide scripts, or Python, as far as I know there is no current implementation built in QGIS;
Search via breadth-first search for the neighbours, and keep on checking whether you got to the population ...