You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vector tiles should deduplicate boundary lines #800
As of #701, the vector tiles represent each boundary relation as a single LineString feature, so if a given way is a member of multiple boundary relations, its coordinates appear in the tile multiple times. This means we still have the performance problem described in #701 (comment) (but slightly worse because we now synthesize centroid points as well), and it still isn’t possible to style a boundary as a dashed line without a conflict between overlapping dash patterns.
The next logical step would be to dissolve the boundary linestring into a sort of planar graph, so that a way in OHM that is a member of many boundary relations will correspond to only one linestring in the tile, with the same endpoints. I wonder if it may be more straightforward to change how we import boundaries, so that we also copy the boundary’s details onto each way, similar to how we’d import route and street relations.
Then we need to coalesce any redundant linestrings. The easy case is to coalesce any boundary edges that share all the same properties, which would be easier once we remove name from the boundary linestrings: #798. However, we still need to include redundant linestrings in some situations. For example, a way may have been part of a boundary between the years 1800 and 1850 (via multiple relations), then stopped being part of a boundary for 50 years, then became part of a different boundary from 1900 to present (via multiple relations).
I was experimenting with the imports to solve the maritime issue in #744. I verified that it is possible to import the parts of relations for the tag boundary=administrative as LineString. We could work with the members (ways) that only belong to an administrative boundary, which would help reduce the number of repeated geometric lines.
The import table may look like this: 👇
working with the table , A SQL query can group these members (ways) that have the same ID and store the attributes of the relation to which this member belongs in a JSON column. This way, we would have just one geometric line, with attributes that belong to that way in columns and an array of the relations to which it belongs. 👇
Finally the result could looks like this: 👇
The relations column won't show as an object; it is coming as a string in the vtiles. This may still need to be parsed the object during the styling process.
Nice, I’m glad that you’re able to group by way ID like that.
The relations column won't show as an object; it is coming as a string in the vtiles. This may still need to be parsed the object during the styling process.
The MVT format doesn’t support nesting an object inside feature properties anyways. There’s some talk of supporting it for a successor to the MVT format: maplibre/maplibre-tile-spec#12.
Anyways, the stylesheet doesn’t really need information about individual relations. All it needs is the overall aggregated start and end date(s) in order to know when to filter the feature, and the admin_level in common among all the relations.
I think something flatter like this would be more usable on the client side:
Key
Value
feature id
120
osm_id
178
start_date
1872 (minimum consecutive value)
end_date
null (maximum consecutive value)
admin_level
2 (minimum value)
Key
Value
feature id
1131
osm_id
1876
start_date
1802 (minimum consecutive value)
end_date
null (maximum consecutive value)
admin_level
2 (minimum value)
Not sure how feasible it’ll be in pure SQL. We might need to implement a custom function to coalesce adjacent date ranges.
From the above image, I have added the end_date, which is 1919 seems for dates(years) will work for min and max values , but what about if there are gaps ?
Key
Value
feature id
120
osm_id
178
start_date
1872
end_date
1919
admin_level
2
For admin level maybe we could consider something like 👇
admin_level_1=No admin_level_2 = yes admin_level_3 = No admin_level_4 = yes
From the above image, I have added the end_date, which is 1919 seems for dates(years) will work for min and max values , but what about if there are gaps ?
Ideally, we’d have two distinct features, one representing the time period before the gap and the other representing the time period after the gap (and so on).
If that isn’t feasible, I suppose we could come up with a scheme like start_date_2, but it would be more difficult for the time slider or similar client-side code to filter out.
For admin level maybe we could consider something like 👇
This would be a fine scheme if the styles need to indicate that there are overlapping boundaries at multiple levels. However, I haven’t encountered that need so far in OSM. Normally, a map only cares about the most important (lowest-numbered) level along a given boundary in a given time period. So admin_level would be just 2, but if the boundary changes levels at some point during the date range, then there would be two features. I guess this means we’d have to group by the admin_level in addition to the relation ID?
Currently, each relation is rendered as a polygon, which is then converted to lines for serving in vector tiles. However, this approach is expensive due to the complexity of the geometries.
Example:
A single way could belong to 377 relations in a given area, meaning 377 lines are generated in the vector tiles. This results in heavy tiles and slower quering.
New Approach:
The new method groups data by member ID and admin_level, evaluating the start_date and end_date.
If a way (member) belongs to multiple relations, the function identifies the earliest start_date and the latest end_date. Instead of generating multiple lines for each relation, it creates a single line with the extreme date values.
Admin Level Grouping:
Each way is grouped by admin_level.
If a way belongs to different admin_levels, it will generate separate lines for each admin_level. This means that a single way can have a maximum of 10 lines, one per admin_level (from 1 to 10). This approach ensures that different administrative boundaries are preserved while reducing redundancy.
Example:
Consider Way 198892647 , which belongs to 1169 relations with admin_level=8: With the new approach, these relations are merged into a single line instead of generating multiple separate lines.
Handling Gaps:
If there are gaps between dates (e.g., different start and end dates), separate lines are generated accordingly.
Attributes Considered:
For ohm_land_lines, only necessary attributes included in the final to display the boundary lines
e.g
If a way belongs to different admin_levels, it will generate separate lines for each admin_level. This means that a single way can have a maximum of 10 lines, one per admin_level (from 1 to 10). This approach ensures that different administrative boundaries are preserved while reducing redundancy.
This is a good solution to the general problem. Are there any other attributes that might force us to have a separate feature? If the name=* changes, will a separate centroid point still be generated from the relevant boundary relations?
If there are gaps between dates (e.g., different start and end dates), separate lines are generated accordingly.
Fantastic, thanks! How are we determining whether there’s a gap? For example, is there a gap if one feature ends in 1234 and the other begins in 1235?
Fantastic, thanks! How are we determining whether there’s a gap? For example, is there a gap if one feature ends in 1234 and the other begins in 1235?
I am using the LAG function to access the end_decdate value from the previous row.
LAG(end_decdate) OVER (
PARTITION BY admin_level, member, type
ORDER BY start_decdate
) AS prev_end
Once we have the end date from the previous row, we make a comparison to check if they are the same or if there is an overlap. In other case there is a gap
I tested this in San José, California. The boundary import in codeforsanjose/OSM-SouthBay#28 made sure to separate each end_date=* from each start_date=* by a day, under the assumption that the cutoff time was right at the stroke of midnight. As far as I can tell, the deduplication on staging is working as expected. The difference between production and staging is so stark that the inspector popup no longer lags as you move the cursor around, and each linestring feature is more or less unique.
The resulting features only contain start_decdate and end_decdate properties, without the original start_date and end_date properties. Should we include the string variants too? maplibre-gl-dates and leaflet-ohm-timeslider-v2 both prefer the decimal variants for performance reasons, but I suppose some other data consumers could be reading the string variants instead, depending on the available client-side date functionality. The string variants also distinguish between day, month, and year precision. (In the future, EDTF support in #15 (comment) will probably lead us to expose strings anyways.)
The resulting features only contain start_decdate and end_decdate properties, without the original start_date and end_date properties. Should we include the string variants too?
Those values can be added. I am going to update the query to include those attributes.
I have also realized that the new approach is displaying incomplete relations, since we are evaluating at the member level and not at the polygon/relation level. There may be some new boundaries displayed in staging.
Those admin lines will be displayed in the vector tiles, but not the centroids, because centroids are still using a relation/polygon approach.
I have also realized that the new approach is displaying incomplete relations, since we are evaluating at the member level and not at the polygon/relation level. There may be some new boundaries displayed in staging.
That’s actually a good thing. One common problem over the past year has been boundaries disappearing due to slight gaps. It’s good to give mappers feedback about errors like that, but the whole boundary going away was a bit harsh. I think it would be a better balance to show the (incomplete) boundary line but not the centroid, as is the case on staging.
This also gives us an option for boundaries that were incompletely defined in the real world, without forcing us to close the loop with conjectural ways. In that case, mappers will just need to create the place=* point manually and relate it to the boundary as a label member.
We’ve been tagging individual boundary ways for both maritime boundaries and disputed boundaries. We’ll need to make sure those attributes persist in the tiles too.
We’ve been tagging individual boundary ways for both maritime boundaries and disputed boundaries. We’ll need to make sure those attributes persist in the tiles too.
Could you provide those attributes, in order to add in the lines.
Actually, adding start_date and end_date as strings is not posible. Currently, for merging the lines, we are evaluating the numeric values start_decdate and end_decdate. We use the MIN and MAX functions to determine these values. However, if we apply the same approach to start_date and end_date as strings, it results in incorrect values since those values are stored as text. How important would it be to have those attributes? Can they be displayed in an array list the hole values for start_date an end_date?
We’ve been tagging individual boundary ways for both maritime boundaries and disputed boundaries. We’ll need to make sure those attributes persist in the tiles too.
Could you provide those attributes, in order to add in the lines.
After looking at it more closely, maritime=yes seems to occur more frequently withoutboundary=* on individual ways, so we’re probably good there as long as we don’t regress the maritime property that you added in #744.
Disputed boundaries can have keys such as disputed_by=* and claimed_by=*, but we haven’t implemented that yet: #553. Don’t worry about this for now; we can tackle it later. We probably need to have a community discussion about how to model conflicting claims in general.
Indefinite or indeterminate boundaries are tagged indefinite=* or indeterminate=* on the individual member ways, again without boundary=*. Similarly, we haven’t implemented this yet, so don’t worry about it unless you think this approach will make it more difficult to support in the future.
Actually, adding start_date and end_date as strings is not posible. Currently, for merging the lines, we are evaluating the numeric values start_decdate and end_decdate. We use the MIN and MAX functions to determine these values. However, if we apply the same approach to start_date and end_date as strings, it results in incorrect values since those values are stored as text. How important would it be to have those attributes? Can they be displayed in an array list the hole values for start_date an end_date?
Existing styles assume start_date and end_date are strings in YYYY, YYYY-MM, or YYYY-MM-DD format and will probably break if they’re in some other format. (MVT doesn’t support arrays as feature property values anyways.)
Based on this documentation, it should be possible to compare strings lexicographically (alphabetically). Since these keys only accept ISO 8601-like values, this should be an accurate sort. The only caveat is that these keys also allow YYYY and YYYY-MM formats, which can be more nuanced. For example, 1800 sorts before 1800-01-01, but for end_date we want it to sort after 1800-12-31. I assume the decimal conversion already handles this situation.
Or would it be possible to set the resulting start_date to the start_date of the same original boundary that had the minimum start_decdate? I guess that would be difficult if you’re using some kind of aggregation.
The only caveat is that these keys also allow YYYY and YYYY-MM formats, which can be more nuanced. For example, 1800 sorts before 1800-01-01, but for end_date we want it to sort after 1800-12-31. I assume the decimal conversion already handles this situation.
SELECT
to_date(start_date, 'YYYY-MM-DD') AS start,
(to_date(end_date, 'YYYY-MM-DD') + (CASE
WHEN end_date SIMILAR TO '-?\d+-\d\d-\d\d' THEN '0 days'
WHEN end_date SIMILAR TO '-?\d+-\d\d' THEN '1 month -1 days'
WHEN end_date SIMILAR TO '-?\d+' THEN '1 year -1 days'
END ::INTERVAL)) ::DATEAS end
FROM Element;
I was able to add start_date and end_date from start_decdate and end_decdate, which for now I think is good. It is in the format YYYY-MM-DD, but it may be different in some cases. For example, if the attribute in OHM is 1800, it will turn into 1800-01-01 in the vtiles
After looking at it more closely, maritime=yes seems to occur more frequently without boundary=* on individual ways, so we’re probably good there as long as we don’t regress the maritime property that you added in #744.
I was looking for a way to add the maritime, dispute, indefinite, and indeterminate and claimed_by, etc. It is possible to add them to the lines(ways), but they need to be combined with a relation, I mean the way must belong to a relation. in case it is only a way in won appear on the layer.s Maybe it could be added in another layer, merging maritime, dispute, indefinite... into a single layer.
I have also discovered an issue where boundaries that are ways are not included in the output. there are boundaries that are ways, and these are not being considered yet in this vtile layer. I’ll work on combining another table to include this information while keeping the current simplification.
Finally, I have improved the script to combine two sources. One source comes from relations, which go through a merging process into a single line based on start_decdate and end_decdate, considering overlapping. This processing is stored in a materialized view called mview_relation_members_boundaries . Then, we have another table called osm_admin_lines, which mainly contains administrative way objects.
Both sources are combined into a single materialized view, and from there, additional materialized views are created with admin_level filters and geometry simplifications.
Activity
Rub21 commentedon Jun 11, 2024
I was experimenting with the imports to solve the maritime issue in #744. I verified that it is possible to import the parts of relations for the tag
boundary=administrativeas LineString. We could work with the members (ways) that only belong to an administrative boundary, which would help reduce the number of repeated geometric lines.The import table may look like this: 👇

working with the table , A SQL query can group these members (ways) that have the same ID and store the attributes of the relation to which this member belongs in a JSON column. This way, we would have just one geometric line, with attributes that belong to that way in columns and an array of the relations to which it belongs. 👇
Finally the result could looks like this: 👇
The relations column won't show as an object; it is coming as a string in the vtiles. This may still need to be parsed the object during the styling process.
ref: go-spatial/tegola#664
1ec5 commentedon Jun 12, 2024
Nice, I’m glad that you’re able to group by way ID like that.
The MVT format doesn’t support nesting an object inside feature properties anyways. There’s some talk of supporting it for a successor to the MVT format: maplibre/maplibre-tile-spec#12.
Anyways, the stylesheet doesn’t really need information about individual relations. All it needs is the overall aggregated start and end date(s) in order to know when to filter the feature, and the
admin_levelin common among all the relations.I think something flatter like this would be more usable on the client side:
feature id120osm_id178start_date1872(minimum consecutive value)end_datenull(maximum consecutive value)admin_level2(minimum value)feature id1131osm_id1876start_date1802(minimum consecutive value)end_datenull(maximum consecutive value)admin_level2(minimum value)Not sure how feasible it’ll be in pure SQL. We might need to implement a custom function to coalesce adjacent date ranges.
Rub21 commentedon Jun 13, 2024
From the above image, I have added the end_date, which is
1919seems for dates(years) will work for min and max values , but what about if there are gaps ?feature id120osm_id178start_date1872end_date1919admin_level2For admin level maybe we could consider something like 👇
admin_level_1=Noadmin_level_2= yesadmin_level_3= Noadmin_level_4= yes1ec5 commentedon Jun 13, 2024
Ideally, we’d have two distinct features, one representing the time period before the gap and the other representing the time period after the gap (and so on).
If that isn’t feasible, I suppose we could come up with a scheme like
start_date_2, but it would be more difficult for the time slider or similar client-side code to filter out.This would be a fine scheme if the styles need to indicate that there are overlapping boundaries at multiple levels. However, I haven’t encountered that need so far in OSM. Normally, a map only cares about the most important (lowest-numbered) level along a given boundary in a given time period. So
admin_levelwould be just 2, but if the boundary changes levels at some point during the date range, then there would be two features. I guess this means we’d have to group by theadmin_levelin addition to the relation ID?Rub21 commentedon Mar 11, 2025
Updates Here
I was able to merge the number of boundary lines.
Previous Approach:
Currently, each relation is rendered as a polygon, which is then converted to lines for serving in vector tiles. However, this approach is expensive due to the complexity of the geometries.
Example:
A single way could belong to 377 relations in a given area, meaning 377 lines are generated in the vector tiles. This results in heavy tiles and slower quering.
New Approach:
The new method groups data by member ID and
admin_level, evaluating thestart_dateandend_date.start_dateand the latestend_date. Instead of generating multiple lines for each relation, it creates a single line with the extreme date values.Admin Level Grouping:
Each way is grouped by
admin_level.admin_levels, it will generate separate lines for eachadmin_level. This means that a single way can have a maximum of 10 lines, one peradmin_level(from 1 to 10). This approach ensures that different administrative boundaries are preserved while reducing redundancy.Example:
Consider Way 198892647 , which belongs to 1169 relations with
admin_level=8: With the new approach, these relations are merged into a single line instead of generating multiple separate lines.Handling Gaps:
Attributes Considered:
For
ohm_land_lines, only necessary attributes included in the final to display the boundary linese.g
currently this is deployed in staging, for testing https://staging.openhistoricalmap.org/
cc. @1ec5 @danrademacher
1ec5 commentedon Mar 11, 2025
This is a good solution to the general problem. Are there any other attributes that might force us to have a separate feature? If the
name=*changes, will a separate centroid point still be generated from the relevant boundary relations?Fantastic, thanks! How are we determining whether there’s a gap? For example, is there a gap if one feature ends in
1234and the other begins in1235?Rub21 commentedon Mar 11, 2025
I am using the LAG function to access the end_decdate value from the previous row.
LAG(end_decdate) OVER ( PARTITION BY admin_level, member, type ORDER BY start_decdate ) AS prev_endOnce we have the end date from the previous row, we make a comparison to check if they are the same or if there is an overlap. In other case there is a gap
Script here: https://github.com/OpenHistoricalMap/ohm-deploy/blob/bdd3e45aa19c045d0149403c684e2a896ce4549c/images/tiler-imposm/queries/mviews_admin_boundaries_merged.sql#L62-L65
1ec5 commentedon Mar 11, 2025
I tested this in San José, California. The boundary import in codeforsanjose/OSM-SouthBay#28 made sure to separate each
end_date=*from eachstart_date=*by a day, under the assumption that the cutoff time was right at the stroke of midnight. As far as I can tell, the deduplication on staging is working as expected. The difference between production and staging is so stark that the inspector popup no longer lags as you move the cursor around, and each linestring feature is more or less unique.The resulting features only contain
start_decdateandend_decdateproperties, without the originalstart_dateandend_dateproperties. Should we include the string variants too? maplibre-gl-dates and leaflet-ohm-timeslider-v2 both prefer the decimal variants for performance reasons, but I suppose some other data consumers could be reading the string variants instead, depending on the available client-side date functionality. The string variants also distinguish between day, month, and year precision. (In the future, EDTF support in #15 (comment) will probably lead us to expose strings anyways.)Rub21 commentedon Mar 11, 2025
The resulting features only contain start_decdate and end_decdate properties, without the original start_date and end_date properties. Should we include the string variants too?
Those values can be added. I am going to update the query to include those attributes.
I have also realized that the new approach is displaying incomplete relations, since we are evaluating at the member level and not at the polygon/relation level. There may be some new boundaries displayed in staging.
Those admin lines will be displayed in the vector tiles, but not the centroids, because centroids are still using a relation/polygon approach.
1ec5 commentedon Mar 11, 2025
That’s actually a good thing. One common problem over the past year has been boundaries disappearing due to slight gaps. It’s good to give mappers feedback about errors like that, but the whole boundary going away was a bit harsh. I think it would be a better balance to show the (incomplete) boundary line but not the centroid, as is the case on staging.
This also gives us an option for boundaries that were incompletely defined in the real world, without forcing us to close the loop with conjectural ways. In that case, mappers will just need to create the
place=*point manually and relate it to the boundary as alabelmember.We’ve been tagging individual boundary ways for both maritime boundaries and disputed boundaries. We’ll need to make sure those attributes persist in the tiles too.
Rub21 commentedon Mar 11, 2025
Could you provide those attributes, in order to add in the lines.
Rub21 commentedon Mar 11, 2025
Actually, adding start_date and end_date as strings is not posible. Currently, for merging the lines, we are evaluating the numeric values start_decdate and end_decdate. We use the MIN and MAX functions to determine these values. However, if we apply the same approach to start_date and end_date as strings, it results in incorrect values since those values are stored as text. How important would it be to have those attributes? Can they be displayed in an array list the hole values for start_date an end_date?
1ec5 commentedon Mar 12, 2025
After looking at it more closely,
maritime=yesseems to occur more frequently withoutboundary=*on individual ways, so we’re probably good there as long as we don’t regress themaritimeproperty that you added in #744.Disputed boundaries can have keys such as
disputed_by=*andclaimed_by=*, but we haven’t implemented that yet: #553. Don’t worry about this for now; we can tackle it later. We probably need to have a community discussion about how to model conflicting claims in general.Indefinite or indeterminate boundaries are tagged
indefinite=*orindeterminate=*on the individual member ways, again withoutboundary=*. Similarly, we haven’t implemented this yet, so don’t worry about it unless you think this approach will make it more difficult to support in the future.Existing styles assume
start_dateandend_dateare strings in YYYY, YYYY-MM, or YYYY-MM-DD format and will probably break if they’re in some other format. (MVT doesn’t support arrays as feature property values anyways.)Based on this documentation, it should be possible to compare strings lexicographically (alphabetically). Since these keys only accept ISO 8601-like values, this should be an accurate sort. The only caveat is that these keys also allow YYYY and YYYY-MM formats, which can be more nuanced. For example, 1800 sorts before 1800-01-01, but for
end_datewe want it to sort after 1800-12-31. I assume the decimal conversion already handles this situation.Or would it be possible to set the resulting
start_dateto thestart_dateof the same original boundary that had the minimumstart_decdate? I guess that would be difficult if you’re using some kind of aggregation.1ec5 commentedon Mar 13, 2025
In case it isn’t feasible to hook in the
pad_datefunction from DateFunctions-plpgsql, here’s a simple implementation that should be equivalent:Rub21 commentedon Mar 13, 2025
I was able to add start_date and end_date from start_decdate and end_decdate, which for now I think is good. It is in the format YYYY-MM-DD, but it may be different in some cases. For example, if the attribute in OHM is 1800, it will turn into 1800-01-01 in the vtiles
I was looking for a way to add the maritime, dispute, indefinite, and indeterminate and claimed_by, etc. It is possible to add them to the lines(ways), but they need to be combined with a relation, I mean the way must belong to a relation. in case it is only a way in won appear on the layer.s Maybe it could be added in another layer, merging maritime, dispute, indefinite... into a single layer.
I have also discovered an issue where boundaries that are ways are not included in the output. there are boundaries that are ways, and these are not being considered yet in this vtile layer. I’ll work on combining another table to include this information while keeping the current simplification.
Rub21 commentedon Mar 13, 2025
Finally, I have improved the script to combine two sources. One source comes from relations, which go through a merging process into a single line based on start_decdate and end_decdate, considering overlapping. This processing is stored in a materialized view called
mview_relation_members_boundaries. Then, we have another table called osm_admin_lines, which mainly contains administrative way objects.Both sources are combined into a single materialized view, and from there, additional materialized views are created with admin_level filters and geometry simplifications.
Currently it was deployed in staging https://staging.openhistoricalmap.org/#map=5/37.11/-94.09
1ec5 commentedon Apr 13, 2025
This landed in OpenHistoricalMap/ohm-deploy#494.