CartoDB / observatory-extension

BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

Return the parent id and name for a given geometry #340

Closed antoniocarlon closed 5 years ago

antoniocarlon commented 6 years ago

Return the parent id and name for a given geometry (in the OBS_GetMCDOMVT or in the xyz table generation??)

juanignaciosl commented 6 years ago

Related: CartoDB/Geographica-Product-Coordination/issues/14#issuecomment-415531543

juanignaciosl commented 6 years ago

We have to add the parent names in a semantic way in Tilesets API:

id: '120570051011032'
block_id: '120570051011032'
block_group_id: '120570051011'
county: 'Hillsborough'
state: 'Florida'
...
median_age 27.5
total_pop 317

Keep in mind that a child can have multiple parents.

Implementation:

Two tables, one for the information of each feature, and another for parent/child relationships:

Loading procedure:

  1. Make a ordered list with the level tables, from lowest (blocks) to highest (states).
  2. For each level table: 1.1 For each feature: 1.1.1 Add it to id, type, name table. 1.1.2 Get a point with point on surface. 1.1.3 For each level above the current one (next 2 steps can probably be done in one single query): 1.1.3.1 Intersect the point on surface to get all the parents. 1.1.3.2 Compute the intersection for each one and insert this in the parent/child relationships table.

Note that...

It will be recursively queried to return the tile. If it were slow we'd also precompute it, but that's not likely to happen, as tables should be pretty small.

javitonino commented 6 years ago

How does point on surface reconcile with multiple parents of the same level? This happens with non-hierarchical geometries (IIRC we have some of those).

If you intersect a single point from the child, you are going to only get one parent (assuming a non-overlapping topology). In order to get all parents, you'd need to do a polygon-to-polygon intersection (much slower, I know).

antoniocarlon commented 6 years ago

True, we will need to perform heavy polygon to polygon intersections in those cases. Fortunately, we know them and we can limit those heavy intersections to the non coupled layers, keeping the point on surface approach for the rest

juanignaciosl commented 6 years ago

How does point on surface reconcile with multiple parents of the same level? This happens with non-hierarchical geometries (IIRC we have some of those). ... we know them and we can limit those heavy intersections to the non coupled layers

Which are the geometries where point in polygon is not enough?

antoniocarlon commented 6 years ago

Those where the layer and its parent are not coupled (a feature can have several parents). In US, I think that we won't find this case (except for zipcodes, maybe, I'm not sure)

juanignaciosl commented 5 years ago

ETL: CartoDB/bigmetadata/pull/572 Tiler: CartoDB/do_tiler/pull/38

juanignaciosl commented 5 years ago

Deployed for US.