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

237 exporting point geometry #259

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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)
@@ -207,7 +203,10 @@ class SpatialConversionUtils {
manifestData.add(pairList)
}

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

return manifestData
}
@@ -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()
@@ -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()