-
Notifications
You must be signed in to change notification settings - Fork 823
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
openstreetmap-carto project file for TagInfo #3151
Closed
Closed
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
024a279
Generating a simple taginfo project file from "openstreetmap-carto.st…
ImreSamu 54b3739
replace project name to "OpenStreetMap Carto keys"
ImreSamu 0b32ba4
regenerated - taginfo project file
ImreSamu 4e87eb9
change description to "Default OpenStreetMap.org style using CartoCSS"
ImreSamu 4deb542
some refactoring in parsing
ImreSamu e6fad5c
add ./generate-taginfo-project-file.py to .travis check
ImreSamu 6490f80
add "pip install pyyaml" to .travis ( missing yaml )
ImreSamu 766db86
fix PyYAML install
ImreSamu f563927
fix travis python
ImreSamu 19c222e
fix python travis
ImreSamu cb48f81
fix python travis
ImreSamu 93eeb75
fix travis python3
ImreSamu 7cbf6a1
fix python3 travis
ImreSamu 3544f6c
fix travis
ImreSamu 0d0794d
fix travis python3
ImreSamu 2960203
fix python3 yaml
ImreSamu b59ab9a
fix typos, improve python code, add '-v"
ImreSamu 74db3d3
add "git diff taginfo-openstreetmap-carto.json" to the travis check
ImreSamu fdd5694
sort 'taginfo-openstreetmap-carto.json' by osm key
ImreSamu 79ef7f5
change suggested link to " https://taginfo.openstreetmap.org/projects…
ImreSamu fec1f49
move taginfo files to the new place
ImreSamu 6a5fb1b
fix taginfo-project scripts path
ImreSamu b39eace
using re.IGNORECASE
ImreSamu 461b3db
remove unnecessary close
ImreSamu 8df146a
remoove duplicated example
ImreSamu 07ea490
taginfo: improve documentation / add extra parameters / refactor .travis
ImreSamu 82b272f
taginfo: fix .travis diff
ImreSamu b4476ac
fix travis
ImreSamu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
|
||
The taginfo database keeps the information which projects use which OSM keys and tags | ||
* site: https://taginfo.openstreetmap.org | ||
* wiki: https://wiki.openstreetmap.org/wiki/Taginfo | ||
|
||
Now We can generate only a minimal info - about the used 'keys' | ||
see more https://github.com/gravitystorm/openstreetmap-carto/issues/961 | ||
|
||
### WHEN to run? | ||
* when the `../openstreetmap-carto.style` or `../project.mml` change , this is the 2 input files for detecting osm keys | ||
|
||
### HOW to run: | ||
* from this directory: `python3 ./generate-taginfo-project-file.py` | ||
|
||
### RESULT: | ||
* the new: `taginfo-openstreetmap-carto.json` ( and some debug info in the screen! ) | ||
|
||
### Known limitations | ||
* Only a subset of hstore `tags->` is parsed from the `../project.mml` | ||
* This code tested only on Ubuntu Linux | ||
* Check the result! | ||
|
||
### Examples for parsing | ||
* `tags @> 'capital=>yes'"]` | ||
* `tags ? 'wetland'"` | ||
* `tags->'wetland' ` | ||
* `tags->'leaf_type'` | ||
* `tags @> '"generator:source"=>wind'` | ||
* `tags -> ARRAY['wheelchair',ramp:wheelchair']` | ||
* `tags ?& ARRAY['wheelchair',ramp:wheelchair']` | ||
* `tags ?| ARRAY['wheelchair',ramp:wheelchair']` | ||
|
||
### How to debug: | ||
The taginfo project_list file should contain a link to this repo ( /taginfo-project/taginfo-openstreetmap-carto.json ) | ||
* https://github.com/taginfo/taginfo-projects/blob/master/project_list.txt | ||
|
||
the expected line: | ||
* openstreetmap_carto https://raw.githubusercontent.com/gravitystorm/openstreetmap-carto/master/taginfo-project/taginfo-openstreetmap-carto.json | ||
|
||
After the daily refresh the project info should be find here: | ||
* https://taginfo.openstreetmap.org/projects/openstreetmap_carto | ||
|
||
### Disclaimer and Attribution : This code is based on | ||
* Paul Norman code : https://github.com/osmlab/osm2pgsql_taginfo | ||
* Sven Geggus code : https://github.com/giggls/openstreetmap-carto-de/blob/master/views_osmde/generate_taginfo.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# ------------------------------------------------------------------------------- | ||
# | ||
# This code generate a taginfo project list file (see more https://wiki.openstreetmap.org/wiki/Taginfo/Projects ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generate->generates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, fixed! |
||
# | ||
### Attribution & Disclaimer: | ||
# This code is based on : | ||
# Paul Norman code : https://github.com/osmlab/osm2pgsql_taginfo | ||
# Sven Geggus code : https://github.com/giggls/openstreetmap-carto-de/blob/master/views_osmde/generate_taginfo.py | ||
# ------------------------------------------------------- | ||
|
||
import re | ||
import json | ||
import yaml | ||
import sys | ||
|
||
# ------------------------- parameters ---------------------------- | ||
taginfo = { | ||
"data_format": 1, | ||
"project": { | ||
"name": "OpenStreetMap Carto keys", | ||
"description": "Default OpenStreetMap.org style using CartoCSS", | ||
"project_url": "https://github.com/gravitystorm/openstreetmap-carto", | ||
"contact_name": "openstreetmap-carto maintainers", | ||
"contact_email": "openstreetmap-carto (at) gravitystorm (dot) co (dot) uk" | ||
}, | ||
"tags": [] | ||
} | ||
|
||
osm2pgsql_file = '../openstreetmap-carto.style' | ||
cartocss_project_file = '../project.mml' | ||
search_url = 'https://github.com/gravitystorm/openstreetmap-carto/search?utf8=%E2%9C%93&q=' | ||
# ------------------------------------------------------------------------------- | ||
|
||
|
||
|
||
def processOSMkeys(_ds_geometry,_osmtype,_tag): | ||
key=_tag.split("'")[1].split("=")[0].replace('"','') | ||
if key: | ||
print("--:", _ds_geometry,"->", _osmtype, " key:", key) | ||
if key not in allhstoretags: | ||
k = [ _osmtype ] | ||
allhstoretags[key]=k | ||
elif _osmtype not in allhstoretags[key]: | ||
allhstoretags[key].append(_osmtype) | ||
return | ||
|
||
|
||
# | ||
# Parsing openstreetmap-carto.style file | ||
# | ||
with open( osm2pgsql_file , 'r') as style: | ||
for line in style: | ||
if line[0] == '#': | ||
continue | ||
keyline = line.split() | ||
if len(keyline) != 4: | ||
continue | ||
if keyline[3] == 'delete' or 'nocolumn' in keyline[3]: | ||
continue | ||
key = keyline[1] | ||
object_types = [] | ||
if 'node' in keyline[0]: | ||
object_types.append('node') | ||
if 'way' in keyline[0]: | ||
object_types.append('way') | ||
if 'polygon' in keyline[3]: | ||
object_types.append('area') | ||
|
||
if ('area' in object_types) or ('way' in object_types ): | ||
object_types.append('relation') | ||
|
||
if key not in ('z_order','way_area'): | ||
taginfo["tags"].append( | ||
{ | ||
"key": key, | ||
"object_types": object_types, | ||
"description": "Used in the osm2pgsql database backend, see more in the github repo", | ||
"doc_url": search_url+key | ||
}) | ||
|
||
|
||
|
||
# | ||
# Parsing "project.mml" file for the HSTORE keys ( tags-> ) | ||
# | ||
|
||
|
||
with open( cartocss_project_file , 'r') as f: | ||
newf = yaml.load(f.read()) | ||
f.closed | ||
|
||
|
||
# ---------------------------------- Examples -------------------- | ||
# tags @> 'capital=>yes'"] | ||
# tags ? 'wetland'" | ||
# tags->'wetland' | ||
# tags->'leaf_type' | ||
# tags @> '"generator:source"=>wind' | ||
re_tags_b = re.compile(r"[^a-zA-Z0-9_]tags[^'^)^\[^\]]*'.+?'") | ||
|
||
|
||
# ---------------------------------- Examples -------------------- | ||
# tags -> ARRAY['wheelchair',ramp:wheelchair'] | ||
# tags ?& ARRAY['wheelchair',ramp:wheelchair'] | ||
# tags ?| ARRAY['wheelchair',ramp:wheelchair'] | ||
re_tags_array = re.compile( r"[^a-zA-Z0-9_]tags\s*[@\?-][>&\|]\s*[aA][rR][rR][aA][yY]\[.+?\]" ) | ||
|
||
|
||
allhstoretags={} | ||
|
||
for layer in newf["Layer"]: | ||
print( "########### processing Layer: ", layer["id"]," ###########" ) | ||
ds_geometry = layer.get("geometry") | ||
|
||
|
||
ds_type = layer["Datasource"].get("type") | ||
if ds_type and ds_type == "postgis": | ||
ds_table = layer["Datasource"].get("table") | ||
if ds_table: | ||
|
||
osmtype = '' | ||
if ds_geometry: | ||
if (ds_geometry=='point'): | ||
osmtype='node' | ||
elif ds_geometry=='linestring': | ||
osmtype='way' | ||
elif ds_geometry=='polygon': | ||
osmtype='area' | ||
else: | ||
# If no Geometry type - we try to guess the type. | ||
if 'planet_osm_point' in ds_table.lower(): | ||
osmtype='node' | ||
elif 'planet_osm_polygon' in ds_table.lower(): | ||
osmtype='area' | ||
elif 'planet_osm_line' in ds_table.lower(): | ||
osmtype='way' | ||
elif 'planet_osm_ways' in ds_table.lower(): | ||
osmtype='way' | ||
else: | ||
print( ds_table.lower() ) | ||
|
||
|
||
tags01 = re_tags_b.findall(ds_table) | ||
if tags01: | ||
print(tags01) | ||
for tag in tags01: | ||
processOSMkeys(ds_geometry,osmtype,tag) | ||
|
||
tagsa = re_tags_array.findall(ds_table) | ||
if tagsa: | ||
for tags in tagsa: | ||
for tag in tags.split(','): | ||
processOSMkeys(ds_geometry,osmtype,tag) | ||
|
||
for k in allhstoretags: | ||
# add "relation" if "area" or "way" | ||
if ('area' in allhstoretags[k]) or ('way' in allhstoretags[k]): | ||
allhstoretags[k].append("relation") | ||
|
||
taginfo["tags"].append( | ||
{ | ||
"key": k, | ||
"object_types": allhstoretags[k], | ||
"description": "Used as a hstore tags-> in the database backend, see more in the github repo", | ||
"doc_url": search_url+k | ||
}) | ||
|
||
|
||
|
||
with open('taginfo-openstreetmap-carto.json', 'w') as outfile: | ||
json.dump(taginfo, outfile, indent=4) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have a significant impact on how long it takes us to get a Travis instance