Skip to content

Commit

Permalink
Make the shapefile reader work without GeoTools
Browse files Browse the repository at this point in the history
  • Loading branch information
Kontinuation committed Aug 22, 2024
1 parent 90ac25d commit 034ce1f
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/
package org.apache.sedona.core.formatMapper.shapefileParser.parseUtils.shp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.geotools.geometry.jts.coordinatesequence.CoordinateSequences;
import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
Expand All @@ -44,7 +43,6 @@ public PolygonParser(GeometryFactory geometryFactory) {
*
* @param reader the reader
* @return the geometry
* @throws IOException Signals that an I/O exception has occurred.
*/
@Override
public Geometry parseShape(ShapeReader reader) {
Expand Down Expand Up @@ -72,16 +70,13 @@ public Geometry parseShape(ShapeReader reader) {
LinearRing ring = geometryFactory.createLinearRing(csRing);
if (shell == null) {
shell = ring;
shellsCCW = CoordinateSequences.isCCW(csRing);
} else if (CoordinateSequences.isCCW(csRing) != shellsCCW) {
shellsCCW = Orientation.isCCW(csRing);
} else if (Orientation.isCCW(csRing) != shellsCCW) {
holes.add(ring);
} else {
if (shell != null) {
Polygon polygon =
geometryFactory.createPolygon(shell, GeometryFactory.toLinearRingArray(holes));
polygons.add(polygon);
}

Polygon polygon =
geometryFactory.createPolygon(shell, GeometryFactory.toLinearRingArray(holes));
polygons.add(polygon);
shell = ring;
holes.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class ShapefilePartitionReader(
try {
FunctionsGeoTools.wktCRSToSRID(wkt)
} catch {
case e: Exception =>
case e: Throwable =>
val prjPath = partitionedFilesMap.get("prj").orNull
logger.warn(s"Failed to parse SRID from .prj file $prjPath", e)
0
Expand Down

0 comments on commit 034ce1f

Please sign in to comment.