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

Control OSM data #49

Open
ebocher opened this issue Oct 2, 2017 · 2 comments
Open

Control OSM data #49

ebocher opened this issue Oct 2, 2017 · 2 comments

Comments

@ebocher
Copy link
Member

ebocher commented Oct 2, 2017

As illustrated in the figure below, the objective is to build a processing chain to analyse the quality of OSM data, extracted for a specified area.

control_qulaity_osm

@ebocher
Copy link
Member Author

ebocher commented Nov 20, 2017

The following groovy script could be used from WPS or OrbisGIS groovy console to extract osm buildings from a French commune.

//Set a path for the file
pathOfTheFile = "/tmp/thefile.osm"

//Replace the query
queryURL ="area['ref:INSEE'='56260'][admin_level=8]->.searchArea;way [building](area.searchArea);(._;>;);out;"

apiUrl = "http://overpass-api.de/api/interpreter?data=";
def connection = new URL( apiUrl+URLEncoder.encode(queryURL) ).openConnection() as HttpURLConnection

connection.setRequestMethod("GET")
println connection.responseCode
 
//Save the result in a file
if(connection.responseCode==200){
inputStream = connection.inputStream;
FileOutputStream outputStream = new FileOutputStream(new File(pathOfTheFile));
int BUFFER_SIZE = 4096
int bytesRead = -1;
byte[] buffer = new byte[BUFFER_SIZE];
      while ((bytesRead = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer, 0, bytesRead);
       }
 
outputStream.close();
inputStream.close();
}
else{
     println "Cannot execute the query"
}
//Import file
println "File to import"
sql.execute "CALL OSMREAD('"+ pathOfTheFile+"', 'OSM_BRETAGNE', true)";

sql.execute("DROP TABLE IF EXISTS OSM_BRETAGNE_BUILDINGS;CREATE TABLE OSM_BRETAGNE_BUILDINGS(ID_WAY BIGINT PRIMARY KEY) AS SELECT DISTINCT ID_WAY FROM OSM_BRETAGNE_WAY_TAG WT, OSM_BRETAGNE_TAG T WHERE WT.ID_TAG = T.ID_TAG AND T.TAG_KEY IN ('building'); DROP TABLE IF EXISTS OSM_BRETAGNE_BUILDINGS_GEOM; CREATE TABLE OSM_BRETAGNE_BUILDINGS_GEOM AS SELECT ID_WAY, ST_MAKEPOLYGON(ST_MAKELINE(THE_GEOM)) THE_GEOM FROM (SELECT (SELECT ST_ACCUM(THE_GEOM) THE_GEOM FROM (SELECT N.ID_NODE, N.THE_GEOM,WN.ID_WAY IDWAY FROM OSM_BRETAGNE_NODE N,OSM_BRETAGNE_WAY_NODE WN WHERE N.ID_NODE = WN.ID_NODE ORDER BY WN.NODE_ORDER) WHERE  IDWAY = W.ID_WAY) THE_GEOM ,W.ID_WAY FROM OSM_BRETAGNE_WAY W,OSM_BRETAGNE_BUILDINGS B WHERE W.ID_WAY = B.ID_WAY) GEOM_TABLE WHERE ST_GEOMETRYN(THE_GEOM,1) = ST_GEOMETRYN(THE_GEOM, ST_NUMGEOMETRIES(THE_GEOM)) AND ST_NUMGEOMETRIES(THE_GEOM) > 2;"

@ebocher
Copy link
Member Author

ebocher commented Feb 21, 2018

@nahtanojoal

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

No branches or pull requests

2 participants