Loading src/main/java/es/redmic/utils/geo/convert/GeoUtils.java +14 −10 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ package es.redmic.utils.geo.convert; */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.UUID; Loading @@ -31,12 +30,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import com.bedatadriven.jackson.datatype.jts.JtsModule; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.exception.mediastorage.MSFileNotFoundException; import es.redmic.exception.utils.ProcessErrorException; import es.redmic.jts4jackson.module.JTSModule; import es.redmic.models.es.geojson.common.dto.GeoJSONFeatureCollectionDTO; @Component Loading @@ -45,7 +44,7 @@ public class GeoUtils { FeatureJSON fjson = new FeatureJSON(); ObjectMapper jacksonMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .registerModule(new JTSModule()); .registerModule(new JtsModule()); private final Logger LOGGER = LoggerFactory.getLogger(GeoUtils.class); Loading @@ -60,25 +59,30 @@ public class GeoUtils { String targetFile = folder + "/" + UUID.randomUUID().toString() + ".json"; String[] cmd = { "bash", "-c", "ogr2ogr --config SHAPE_RESTORE_SHX yes -f \"GeoJSON\" " + targetFile + " " + sourceFile }; "ogr2ogr --config SHAPE_RESTORE_SHX yes -f \"GeoJSON\" \"" + targetFile + "\" \"" + sourceFile + "\""}; Process p; try { ProcessBuilder builder = new ProcessBuilder(cmd); builder.redirectErrorStream(true); p = builder.start(); p.waitFor(); int exitCode = p.waitFor(); LOGGER.debug("Program ended with exitCode {}", exitCode); } catch (IOException | InterruptedException e) { LOGGER.debug("Error ejecutando " + cmd[0]); LOGGER.debug("Error ejecutando {}", cmd[0]); throw new ProcessErrorException(e); } File geojsonFile = new File(targetFile); GeoJSONFeatureCollectionDTO collection = null; if (!geojsonFile.exists()) { return collection; } try { FileInputStream geoJson = new FileInputStream(targetFile); collection = jacksonMapper.readValue(geoJson, GeoJSONFeatureCollectionDTO.class); //FileInputStream geoJson = new FileInputStream(geojsonFile); collection = jacksonMapper.readValue(geojsonFile, GeoJSONFeatureCollectionDTO.class); } catch (IOException e) { throw new MSFileNotFoundException(geojsonFile.getName(), folder, e); } Loading src/test/java/es/redmic/test/utils/geo/convert/ConvertShapeFileToGeoJsonTest.java +12 −10 Original line number Diff line number Diff line package es.redmic.test.utils.geo.convert; import static org.junit.Assert.assertNotNull; /*- * #%L * Utils Loading Loading @@ -68,7 +70,7 @@ public class ConvertShapeFileToGeoJsonTest { File file = Paths.get(resource.toURI()).toFile(); GeoJSONFeatureCollectionDTO geojson = geoUtils.convertShpToGeoJSON(file); assertNotNull(geojson); assertTrue(geojson.getFeatures().size() == 1); assertTrue(geojson.getFeatures().get(0) instanceof HashMap); Loading @@ -87,7 +89,7 @@ public class ConvertShapeFileToGeoJsonTest { File file = Paths.get(resource.toURI()).toFile(); GeoJSONFeatureCollectionDTO geojson = geoUtils.convertShpToGeoJSON(file); assertNotNull(geojson); assertTrue(geojson.getFeatures().size() == 1); assertTrue(geojson.getFeatures().get(0) instanceof HashMap); Loading src/test/java/es/redmic/test/utils/geo/performance/SimplifyTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -30,13 +30,13 @@ import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.LineString; import com.bedatadriven.jackson.datatype.jts.JtsModule; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import es.redmic.jts4jackson.module.JTSModule; import es.redmic.models.es.geojson.common.model.Feature; import es.redmic.models.es.geojson.common.model.Properties; import es.redmic.utils.geo.performance.Simplify; Loading @@ -50,7 +50,7 @@ public class SimplifyTest { @Before public void init() throws IllegalArgumentException, IllegalAccessException, IOException { objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.registerModule(new JTSModule()); objectMapper.registerModule(new JtsModule()); InputStream file = getClass().getResource("/data/geo/geojson/" + FILENAME_LINESTRING_GEOJSON).openStream(); Loading Loading
src/main/java/es/redmic/utils/geo/convert/GeoUtils.java +14 −10 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ package es.redmic.utils.geo.convert; */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.UUID; Loading @@ -31,12 +30,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import com.bedatadriven.jackson.datatype.jts.JtsModule; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import es.redmic.exception.mediastorage.MSFileNotFoundException; import es.redmic.exception.utils.ProcessErrorException; import es.redmic.jts4jackson.module.JTSModule; import es.redmic.models.es.geojson.common.dto.GeoJSONFeatureCollectionDTO; @Component Loading @@ -45,7 +44,7 @@ public class GeoUtils { FeatureJSON fjson = new FeatureJSON(); ObjectMapper jacksonMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .registerModule(new JTSModule()); .registerModule(new JtsModule()); private final Logger LOGGER = LoggerFactory.getLogger(GeoUtils.class); Loading @@ -60,25 +59,30 @@ public class GeoUtils { String targetFile = folder + "/" + UUID.randomUUID().toString() + ".json"; String[] cmd = { "bash", "-c", "ogr2ogr --config SHAPE_RESTORE_SHX yes -f \"GeoJSON\" " + targetFile + " " + sourceFile }; "ogr2ogr --config SHAPE_RESTORE_SHX yes -f \"GeoJSON\" \"" + targetFile + "\" \"" + sourceFile + "\""}; Process p; try { ProcessBuilder builder = new ProcessBuilder(cmd); builder.redirectErrorStream(true); p = builder.start(); p.waitFor(); int exitCode = p.waitFor(); LOGGER.debug("Program ended with exitCode {}", exitCode); } catch (IOException | InterruptedException e) { LOGGER.debug("Error ejecutando " + cmd[0]); LOGGER.debug("Error ejecutando {}", cmd[0]); throw new ProcessErrorException(e); } File geojsonFile = new File(targetFile); GeoJSONFeatureCollectionDTO collection = null; if (!geojsonFile.exists()) { return collection; } try { FileInputStream geoJson = new FileInputStream(targetFile); collection = jacksonMapper.readValue(geoJson, GeoJSONFeatureCollectionDTO.class); //FileInputStream geoJson = new FileInputStream(geojsonFile); collection = jacksonMapper.readValue(geojsonFile, GeoJSONFeatureCollectionDTO.class); } catch (IOException e) { throw new MSFileNotFoundException(geojsonFile.getName(), folder, e); } Loading
src/test/java/es/redmic/test/utils/geo/convert/ConvertShapeFileToGeoJsonTest.java +12 −10 Original line number Diff line number Diff line package es.redmic.test.utils.geo.convert; import static org.junit.Assert.assertNotNull; /*- * #%L * Utils Loading Loading @@ -68,7 +70,7 @@ public class ConvertShapeFileToGeoJsonTest { File file = Paths.get(resource.toURI()).toFile(); GeoJSONFeatureCollectionDTO geojson = geoUtils.convertShpToGeoJSON(file); assertNotNull(geojson); assertTrue(geojson.getFeatures().size() == 1); assertTrue(geojson.getFeatures().get(0) instanceof HashMap); Loading @@ -87,7 +89,7 @@ public class ConvertShapeFileToGeoJsonTest { File file = Paths.get(resource.toURI()).toFile(); GeoJSONFeatureCollectionDTO geojson = geoUtils.convertShpToGeoJSON(file); assertNotNull(geojson); assertTrue(geojson.getFeatures().size() == 1); assertTrue(geojson.getFeatures().get(0) instanceof HashMap); Loading
src/test/java/es/redmic/test/utils/geo/performance/SimplifyTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -30,13 +30,13 @@ import org.junit.Test; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.LineString; import com.bedatadriven.jackson.datatype.jts.JtsModule; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import es.redmic.jts4jackson.module.JTSModule; import es.redmic.models.es.geojson.common.model.Feature; import es.redmic.models.es.geojson.common.model.Properties; import es.redmic.utils.geo.performance.Simplify; Loading @@ -50,7 +50,7 @@ public class SimplifyTest { @Before public void init() throws IllegalArgumentException, IllegalAccessException, IOException { objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.registerModule(new JTSModule()); objectMapper.registerModule(new JtsModule()); InputStream file = getClass().getResource("/data/geo/geojson/" + FILENAME_LINESTRING_GEOJSON).openStream(); Loading