Skip to content

Commit

Permalink
#237 Fix for POINT MULTIPOINT LINESTRING MULTILINESTRING geometry export
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Collins committed Jan 21, 2025
1 parent 3f4e6c7 commit 22880e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,7 @@ class SpatialObjectsService {
FileUtils.copyFile(zippedShapeFile, os)
} else if ("kml" == geomtype) {
String wktString = l.get(0).geometry.toText()
String wkttype = "POLYGON"
if (wktString.startsWith("MULTIPOLYGON")) {
wkttype = "MULTIPOLYGON"
} else if (wktString.startsWith("GEOMETRYCOLLECTION")) {
wkttype = "GEOMETRYCOLLECTION"
} else if (wktString.startsWith("MULTIPOINT")) {
wkttype = "MULTIPOINT"
} else if (wktString.startsWith("POINT")) {
wkttype = "POINT"
}

final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wkttype)
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wktString)
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE)
featureBuilder.add(l.get(0).geometry)
SimpleFeature feature = featureBuilder.buildFeature(null)
Expand All @@ -300,17 +289,7 @@ class SpatialObjectsService {
StringWriter writer = new StringWriter()

String wktString = l.get(0).geometry.toText()
String wkttype = "POLYGON"
if (wktString.startsWith("MULTIPOLYGON")) {
wkttype = "MULTIPOLYGON"
} else if (wktString.startsWith("GEOMETRYCOLLECTION")) {
wkttype = "GEOMETRYCOLLECTION"
} else if (wktString.startsWith("MULTIPOINT")) {
wkttype = "MULTIPOINT"
} else if (wktString.startsWith("POINT")) {
wkttype = "POINT"
}
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wkttype)
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wktString)
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE)
featureBuilder.add(l.get(0).geometry)
SimpleFeature feature = featureBuilder.buildFeature(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.apache.commons.io.filefilter.IOFileFilter
import org.apache.commons.lang3.tuple.Pair
import org.geotools.data.DefaultTransaction
import org.geotools.data.FileDataStore
Expand All @@ -26,7 +25,11 @@ import org.geotools.referencing.CRS
import org.geotools.referencing.crs.DefaultGeographicCRS
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.GeometryCollection
import org.locationtech.jts.geom.LineString
import org.locationtech.jts.geom.MultiLineString
import org.locationtech.jts.geom.MultiPoint
import org.locationtech.jts.geom.MultiPolygon
import org.locationtech.jts.geom.Point
import org.locationtech.jts.geom.Polygon
import org.locationtech.jts.io.ParseException
import org.locationtech.jts.io.WKTReader
Expand All @@ -49,13 +52,6 @@ import java.util.zip.ZipOutputStream
@CompileStatic
class SpatialConversionUtils {

public final static String WKT_MAP_KEY = "WKT_MAP_KEY_****"
//works as long as this is not uploaded as a field in the shapefile
/**
* log4j logger
*/
//private static final Logger logger = log.getLogger(SpatialConversionUtils.class);

static List<String> getGeometryCollectionParts(String wkt) {
if (wkt.matches("GEOMETRYCOLLECTION\\(.+\\)")) {
String parts = wkt.substring(19, wkt.length() - 1)
Expand Down Expand Up @@ -207,7 +203,10 @@ class SpatialConversionUtils {
manifestData.add(pairList)
}

// it.close();
try {
store.dispose()
} catch (Exception ignored) {
}

return manifestData
}
Expand Down Expand Up @@ -242,8 +241,7 @@ class SpatialConversionUtils {
SimpleFeatureCollection featureCollection = featureSource.getFeatures()
it = featureCollection.features()

//transform CRS to the same as the shapefile (at least try)
//default to 4326
//transform CRS to the same as the shapefile (at least try) default to 4326
CoordinateReferenceSystem crs = null
try {
crs = store.getSchema().getCoordinateReferenceSystem()
Expand Down Expand Up @@ -448,26 +446,30 @@ class SpatialConversionUtils {
}
}

private static SimpleFeatureType createFeatureType(String type) {
static SimpleFeatureType createFeatureType(String type) {

SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder()
builder.setName("ActiveArea")
builder.setCRS(DefaultGeographicCRS.WGS84) // <- Coordinate reference
// system
builder.setCRS(DefaultGeographicCRS.WGS84) // <- Coordinate reference system

// add attributes in order
if ("GEOMETRYCOLLECTION".equalsIgnoreCase(type)) {
builder.add("the_geom", MultiPolygon.class)
} else if ("MULTIPOLYGON".equalsIgnoreCase(type)) {
builder.add("the_geom", MultiPolygon.class)
} else if ("LINESTRING".equalsIgnoreCase(type)) {
builder.add("the_geom", LineString.class)
} else if ("MULTILINESTRING".equalsIgnoreCase(type)) {
builder.add("the_geom", MultiLineString.class)
} else if ("POINT".equalsIgnoreCase(type)) {
builder.add("the_geom", Point.class)
} else if ("MULTIPOINT".equalsIgnoreCase(type)) {
builder.add("the_geom", MultiPoint.class)
} else {
builder.add("the_geom", Polygon.class)
}
builder.length(50).add("name", String.class) // <- 50 chars width for
// name field
builder.length(100).add("desc", String.class) // 100 chars width
// for description
// field
builder.length(50).add("name", String.class) // <- 50 chars width for name field
builder.length(100).add("desc", String.class) // 100 chars width for description field

// build the type
return builder.buildFeatureType()
Expand Down

0 comments on commit 22880e3

Please sign in to comment.