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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added missing file
  • Loading branch information
satol committed May 28, 2018
commit 13c1fa322441f8a24d89899a5a6d54454a2b467a
89 changes: 89 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,89 @@
/*
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;

import java.util.ArrayList;
import java.util.List;

import com.esri.core.geometry.ogc.OGCConcreteGeometryCollection;
import com.esri.core.geometry.ogc.OGCGeometry;
import com.esri.core.geometry.ogc.OGCGeometryCollection;

//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);
}
}