Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid geometries generated with Area of Intereset #339

Closed
Algunenano opened this issue Nov 13, 2017 · 1 comment
Closed

Invalid geometries generated with Area of Intereset #339

Algunenano opened this issue Nov 13, 2017 · 1 comment
Labels

Comments

@Algunenano
Copy link
Contributor

When using Area of Interest analysis with points close to the map margins (~180º longitude) invalid polygons are generated, covering the whole world:
image

Carto file with an example: carto.zip

The query to generate the analysis was:

CREATE TABLE analysis_2f13a3dbd7_d79a52e91998c27b34e4665ff11165508de12e92 AS
SELECT * FROM (SELECT
ST_Buffer(the_geom::geography, 8000)::geometry the_geom,cartodb_id,magnst,nst,magsource,locationsource,status,type,place,id,net,magtype,magerror,deptherror,horizontalerror,rms,dmin,gap,mag,depth,longitude,latitude,updated,time
FROM (SELECT * FROM all_month) _camshaft_buffer) _analysis_create_table_query
LIMIT 0

An example from that dataset with the issue:
Point in the dataset:

Select ST_AsEWKT("the_geom_webmercator"),latitude,longitude from all_month where cartodb_id = 3139;
                      st_asewkt                       | latitude | longitude 
------------------------------------------------------+----------+-----------
 SRID=3857;POINT(-20033901.5912875 -2815360.03290273) | -24.5074 | -179.9676

Point after buffer (invalid render both in builder and in Qgis):

Select ST_AsEWKT("the_geom"),latitude,longitude from analysis_2f13a3dbd7_d79a52e91998c27b34e4665ff11165508de12e92 where cartodb_id = 3139;
                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                          
                            st_asewkt                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                          
                                                                  | latitude | longitude 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------+----------+-----------
 SRID=4326;POLYGON((-179.888736236903 -24.5089311174815,-179.890574015504 -24.522980009554,-179.895373178666 -24.5364307183352,-179.90295004877 -24.5487659985138,-179.913013887712 -24.5595113765843,-179.925178002368 -24.5682534509015,-179.938974595903 -24.5746558492224,-179.9538727
95839 -24.5784722196264,-179.969299158455 -24.5795557456198,-179.984659845753 -24.5778648122829,-179.999363601243 -24.5734646019158,179.987155382308 -24.5665245583696,179.975415604496 -24.5573118222547,179.965868265902 -24.5461808975537,179.958879922004 -24.5335599571771,179.954718
449798 -24.5199343247056,179.953542858056 -24.5058277768944,179.955397316563 -24.491782392564,179.960209612269 -24.4783377255956,179.967794068248 -24.4660101014935,179.977858791506 -24.4552728281988,179.990016954279 -24.4465380734785,-179.996198334157 -24.4401410952308,-179.9813161
3736 -24.4363274202147,-179.965907462713 -24.435243454572,-179.950563455368 -24.4369308801543,-179.935872832433 -24.4413250486881,-179.922399401827 -24.4482574361412,-179.910660508275 -24.4574620674774,-179.901107217752 -24.4685856725939,-179.894106991872 -24.4812011929179,-179.889
929516558 -24.4948241300181,-179.888736236903 -24.5089311174815)) | -24.5074 | -179.9676

Some info from CartoDB/crankshaft#187 (comment) by @rafatower:
I'm pretty sure the "offending" query is generated in camshaft:

Buffer.prototype.radiusQuery = function() {
var _columns = [
'ST_Buffer(the_geom::geography, ' + this.radius + ')::geometry the_geom'
].concat(this.source.getColumns(true));
return radiusQueryTpl({
_columns: _columns.join(','),
_query: this.source.getQuery()
});
};
Buffer.prototype.radiusDissolvedQuery = function() {
return radiusQueryTpl({
_columns: [
'row_number() over() AS cartodb_id',
'ST_Union(ST_Buffer(the_geom::geography, ' + this.radius + ')::geometry) the_geom',
].join(', '),
_query: this.source.getQuery()
});
};

though I don't know how hard is to solve these "corner cases" around 180º long. It is kind of a generic problem with geometry types and postgis.

For this very instance the trick may be splitting the geography polygons around 180º before casting back to geometry. Take a look at this post: https://carto.com/blog/jets-and-datelines/

@Algunenano
Copy link
Contributor Author

Stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant