Skip to content

Commit

Permalink
Fix the issues orbisgis#994 and orbisgis#995
Browse files Browse the repository at this point in the history
  • Loading branch information
ebocher committed Sep 16, 2024
1 parent b394b4f commit 3909098
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -846,36 +846,49 @@ static float getHeightRoof(height, heightPattern) {
def match2_group1 = matcher.group(1)
def match2_group2 = matcher.group(2)
if (match1_group1) {
new_h = Float.parseFloat(match1_group1) * 12
new_h = parseFloat(match1_group1) * 12
}
if (match2_group2 == "''") {
new_h += Float.parseFloat(match2_group1)
new_h += parseFloat(match2_group1)
}
return new_h * 0.0254

} else {
if (match1_group1 && match1_group2 == null) {
return Float.parseFloat(match1_group1)
return parseFloat(match1_group1)
}
//next mach for feet, inch matcher.find();
else {
def type = match1_group2.toLowerCase()
switch (type) {
case "m":
return Float.parseFloat(match1_group1)
return parseFloat(match1_group1)
case "foot":
return Float.parseFloat(match1_group1) * 0.3048
return parseFloat(match1_group1) * 0.3048
case "'":
return Float.parseFloat(match1_group1) * 12 * 0.0254
return parseFloat(match1_group1) * 12 * 0.0254
case "''":
return Float.parseFloat(match1_group1) * 0.0254
return parseFloat(match1_group1) * 0.0254
default:
return 0
}
}
}
}

/**
* Parse to float otherwise return 0
* @param value to parse
* @return a float value
*/
static Float parseFloat(def value){
try {
return Float.parseFloat(value)
}catch (NumberFormatException ex){
return 0
}
}

/**
* This function defines the value of the column nb_lev according to the values of b_lev and r_lev
* @param row The row of the raw table to examine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class InputDataFormattingTest {

//zoneToExtract = [62.2, 28.2, 62.4, 28.4]

zoneToExtract =[47.0619, -1.8145005, 47.394558, -1.2849174]
zoneToExtract =[51.328681,1.195128,51.331121,1.199162]
Map extractData = OSM.InputDataLoading.extractAndCreateGISLayers(h2GIS, zoneToExtract)

String formatedPlaceName = zoneToExtract.join("_").trim().split("\\s*(,|\\s)\\s*").join("_");
Expand Down Expand Up @@ -383,4 +383,10 @@ class InputDataFormattingTest {
def road = OSM.InputDataFormatting.formatRoadLayer(h2GIS, gISLayers.road)
h2GIS.getTable(road).save("/tmp/formated_osm_road.shp", true)
}

@Test
void parseFloat() {
def heightPattern = Pattern.compile("((?:\\d+\\/|(?:\\d+|^|\\s)\\.)?\\d+)\\s*([^\\s\\d+\\-.,:;^\\/]+(?:\\^\\d+(?:\$|(?=[\\s:;\\/])))?(?:\\/[^\\s\\d+\\-.,:;^\\/]+(?:\\^\\d+(?:\$|(?=[\\s:;\\/])))?)*)?", Pattern.CASE_INSENSITIVE)
assertEquals(0, InputDataFormatting.getHeightRoof("II OSK 1559/12", heightPattern))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {
def nominatim = org.orbisgis.geoclimate.osmtools.OSMTools.Utilities.getNominatimData(location)
def grid_size = 250
location = nominatim.bbox
//location=[46.178404,6.095524,46.222959,6.190109]
location=[51.2, 1.0, 51.4, 1.2]
/* location =[ 48.84017284026897,
2.3061887733275785,
48.878115442982086,
Expand All @@ -678,7 +678,7 @@ class WorflowOSMTest extends WorkflowAbstractTest {
"parameters" :
["distance" : 0,
"rsu_indicators" : [
"indicatorUse": ["LCZ"]//, "TEB"] //, "UTRF"]
"indicatorUse": ["LCZ", "TEB"] //, "UTRF"]

], "grid_indicators" : [
"x_size" : grid_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ String extractWaysAsPolygons(JdbcDataSource datasource, String osmTablesPrefix,
query += """ a.the_geom ${OSMTools.TransformUtils.createTagList(datasource, columnsSelector, columnsToKeep)} """
}

query += " FROM $waysPolygonTmp AS a, $osmTableTag b WHERE a.id_way=b.id_way and st_isempty(a.the_geom)=false "
query += " FROM $waysPolygonTmp AS a, $osmTableTag b WHERE a.id_way=b.id_way and st_isempty(a.the_geom)=false and st_isvalid(a.the_geom) "

if (columnsToKeep) {
query += " AND b.TAG_KEY IN ('${columnsToKeep.join("','")}') "
Expand Down Expand Up @@ -567,7 +567,7 @@ def extractRelationsAsPolygons(JdbcDataSource datasource, String osmTablesPrefix
} else {
query += """ st_normalize(a.the_geom) as the_geom ${OSMTools.TransformUtils.createTagList(datasource, columnsSelector, columnsToKeep)}
FROM $relationsMpHoles AS a, ${osmTablesPrefix}_relation_tag b
WHERE a.id_relation=b.id_relation and st_isempty(a.the_geom)=false """
WHERE a.id_relation=b.id_relation and st_isempty(a.the_geom)=false and st_isvalid(a.the_geom) """
}

if (columnsToKeep) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class TransformTest extends AbstractOSMToolsTest {

String result = OSMTools.Transform.extractRelationsAsPolygons(ds, prefix, epsgCode, tags, columnsToKeep)
assertFalse result.isEmpty()
ds.save(result, "/tmp/building.geojson", true)
//ds.save(result, "/tmp/building.geojson", true)
def table = ds.getTable(result)
assertEquals 0, table.rowCount

Expand Down

0 comments on commit 3909098

Please sign in to comment.