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

Stolstov/collection methods #178

Merged
merged 19 commits into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/main/java/com/esri/core/geometry/Geometry.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public static int getDimensionFromType(int type) {
* @param type
* The integer value from geometry enumeration. You can use the
* method {@link Type#value()} to get at the integer value.
* @return TRUE if the geometry is a point.
* @return TRUE if the geometry is a point (a Point or a Multipoint).
*/
public static boolean isPoint(int type) {
return (type & 0x20) != 0;
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/com/esri/core/geometry/OGCStructureInternal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 1995-2018 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

For additional information, contact:
Environmental Systems Research Institute, Inc.
Attn: Contracts Dept
380 New York Street
Redlands, California, USA 92373

email: contracts@esri.com
*/
package com.esri.core.geometry;

//An internal helper class. Do not use.
public class OGCStructureInternal {
private static class EditShapeCursor extends GeometryCursor {
EditShape m_shape;
int m_geom;
int m_index;

EditShapeCursor(EditShape shape, int index) {
m_shape = shape;
m_geom = -1;
m_index = index;
}
@Override
public Geometry next() {
if (m_shape != null) {
if (m_geom == -1)
m_geom = m_shape.getFirstGeometry();
else
m_geom = m_shape.getNextGeometry(m_geom);

if (m_geom == -1) {
m_shape = null;
}
else {
return m_shape.getGeometry(m_geom);
}

}

return null;
}

@Override
public int getGeometryID() {
return m_shape.getGeometryUserIndex(m_geom, m_index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_shape can be null, in which case this will throw NPE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok to crash as this is internal method and calling getGeometryID after iterator was exhausted is a bug.

}

};

public static GeometryCursor prepare_for_ops_(GeometryCursor geoms, SpatialReference sr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this method simplifies the shapes. Would it be clearer to rename it to simplify or implement a SimplifyingGeometryCursor instead to match FlatteningGeometryCursor pattern?

assert(geoms != null);
EditShape editShape = new EditShape();
int geomIndex = editShape.createGeometryUserIndex();
for (Geometry g = geoms.next(); g != null; g = geoms.next()) {
int egeom = editShape.addGeometry(g);
editShape.setGeometryUserIndex(egeom, geomIndex, geoms.getGeometryID());
}

Envelope2D env = editShape.getEnvelope2D();
double tolerance = InternalUtils.calculateToleranceFromGeometry(sr,
env, true);

CrackAndCluster.execute(editShape, tolerance, null, true);
return OperatorSimplifyOGC.local().execute(new EditShapeCursor(editShape, geomIndex), sr, false, null);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ static Geometry difference(Geometry geometry_a, Geometry geometry_b,
if (!env_a_inflated.isIntersecting(env_b))
return geometry_a;

if (dimension_a == 1 && dimension_b == 2)
return polylineMinusArea_(geometry_a, geometry_b, type_b,
spatial_reference, progress_tracker);

if (type_a == Geometry.GeometryType.Point) {
Geometry geometry_b_;
if (MultiPath.isSegment(type_b)) {
Expand Down Expand Up @@ -357,36 +353,5 @@ static Geometry multiPointMinusPoint_(MultiPoint multi_point, Point point,

return new_multipoint;
}

static Geometry polylineMinusArea_(Geometry geometry, Geometry area,
int area_type, SpatialReference sr, ProgressTracker progress_tracker) {
// construct the complement of the Polygon (or Envelope)
Envelope envelope = new Envelope();
geometry.queryEnvelope(envelope);
Envelope2D env_2D = new Envelope2D();
area.queryEnvelope2D(env_2D);
envelope.merge(env_2D);
double dw = 0.1 * envelope.getWidth();
double dh = 0.1 * envelope.getHeight();
envelope.inflate(dw, dh);

Polygon complement = new Polygon();
complement.addEnvelope(envelope, false);

MultiPathImpl complementImpl = (MultiPathImpl) (complement._getImpl());

if (area_type == Geometry.GeometryType.Polygon) {
MultiPathImpl polygonImpl = (MultiPathImpl) (area._getImpl());
complementImpl.add(polygonImpl, true);
} else
complementImpl.addEnvelope((Envelope) (area), true);

OperatorFactoryLocal projEnv = OperatorFactoryLocal.getInstance();
OperatorIntersection operatorIntersection = (OperatorIntersection) projEnv
.getOperator(Operator.Type.Intersection);
Geometry difference = operatorIntersection.execute(geometry,
complement, sr, progress_tracker);
return difference;
}

}

Loading