Skip to content

Commit

Permalink
Add point location option to bdtopo module
Browse files Browse the repository at this point in the history
The distance to compute the bbox from a point must be at least 100 meters
  • Loading branch information
ebocher committed Jan 18, 2024
1 parent a7e2cad commit c4ec7ca
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ Integer loadDataFromPostGIS(Object input_database_properties, Object code, Objec
//Check if code is a string or a bbox
//The zone is a osm bounding box represented by ymin,xmin , ymax,xmax,
if (code in Collection) {
//def tmp_insee = code.join("_")
if(code.size()==3){
if(code[2]<100){
error("The distance to create a bbox from a point must be greater than 100 meters")
return
}
code = BDTopoUtils.bbox(code[0], code[1],code[2])
}
String inputTableName = """(SELECT
ST_INTERSECTION(st_setsrid(the_geom, $commune_srid), ST_MakeEnvelope(${code[1]},${code[0]},${code[3]},${code[2]}, $commune_srid)) as the_geom, CODE_INSEE from $commune_location where
st_setsrid(the_geom, $commune_srid)
Expand Down Expand Up @@ -306,6 +312,13 @@ def filterLinkedShapeFiles(def location, float distance, LinkedHashMap inputTabl
//Check if code is a string or a bbox
//The zone is a osm bounding box represented by ymin,xmin , ymax,xmax,
if (location in Collection) {
if(location.size()==3){
if(location[2]<100){
error("The distance to create a bbox from a point must be greater than 100 meters")
return
}
location = BDTopoUtils.bbox(location[0], location[1],location[2])
}
debug "Loading in the H2GIS database $outputTableName"
h2gis_datasource.execute("""DROP TABLE IF EXISTS $outputTableName ; CREATE TABLE $outputTableName as SELECT
ST_INTERSECTION(the_geom, ST_MakeEnvelope(${location[1]},${location[0]},${location[3]},${location[2]}, $sourceSRID)) as the_geom, CODE_INSEE from ${inputTables.commune} where the_geom
Expand All @@ -314,6 +327,8 @@ def filterLinkedShapeFiles(def location, float distance, LinkedHashMap inputTabl
debug "Loading in the H2GIS database $outputTableName"
h2gis_datasource.execute("""DROP TABLE IF EXISTS $outputTableName ; CREATE TABLE $outputTableName as SELECT $formatting_geom,
CODE_INSEE FROM ${inputTables.commune} WHERE CODE_INSEE='$location' or lower(nom)='${location.toLowerCase()}'""".toString())
}else{
return
}
def count = h2gis_datasource."$outputTableName".rowCount
if (count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ def filterLinkedShapeFiles(def location, float distance, LinkedHashMap inputTabl
debug "Loading in the H2GIS database $outputTableName"
def communeColumns = h2gis_datasource.getColumnNames(inputTables.commune)
if(communeColumns.contains("INSEE_COM")) {
if(location.size()==3){
if(location[2]<100){
error("The distance to create a bbox from a point must be greater than 100 meters")
return
}
location = BDTopoUtils.bbox(location[0], location[1],location[2])
}

h2gis_datasource.execute("""DROP TABLE IF EXISTS $outputTableName ; CREATE TABLE $outputTableName as SELECT
ST_INTERSECTION(the_geom, ST_MakeEnvelope(${location[1]},${location[0]},${location[3]},${location[2]}, $sourceSRID)) as the_geom, INSEE_COM AS CODE_INSEE from ${inputTables.commune} where the_geom
&& ST_MakeEnvelope(${location[1]},${location[0]},${location[3]},${location[2]}, $sourceSRID) """.toString())
Expand Down Expand Up @@ -261,6 +269,13 @@ Integer loadDataFromPostGIS(Object input_database_properties, Object code, Objec
if (code in Collection) {
def communeColumns = h2gis_datasource.getColumnNames(commune_location)
if(communeColumns.contains("INSEE_COM")) {
if(code.size()==3){
if(code[2]<100){
error("The distance to create a bbox from a point must be greater than 100 meters")
return
}
code = BDTopoUtils.bbox(code[0], code[1],code[2])
}
String inputTableName = """(SELECT
ST_INTERSECTION(st_setsrid(the_geom, $commune_srid), ST_MakeEnvelope(${code[1]},${code[0]},${code[3]},${code[2]}, $commune_srid)) as the_geom, INSEE_COM as CODE_INSEE from $commune_location where
st_setsrid(the_geom, $commune_srid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ Geometry geometryFromValues(def bbox) {
return buildGeometry([bbox[1], bbox[0], bbox[3], bbox[2]]);
}
else if (bbox.size()==3){
if(bbox[2]<=0){
if(bbox[2]<100){
error("The distance to create a bbox from a point must be greater than 100 meters")
return null
}
return getAreaFromPoint(bbox[1], bbox[0], bbox[2])
Expand Down

0 comments on commit c4ec7ca

Please sign in to comment.