Java Code Examples for org.geotools.data.shapefile.ShapefileDataStore#dispose()

The following examples show how to use org.geotools.data.shapefile.ShapefileDataStore#dispose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamaShapeFile.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected CoordinateReferenceSystem getOwnCRS(final IScope scope) {
	ShapefileDataStore store = null;
	try {
		final URL url = getFile(scope).toURI().toURL();
		store = getDataStore(url);
		CoordinateReferenceSystem crs = store.getFeatureSource().getInfo().getCRS();
		if (crs == null) {
			crs = GISUtils.manageGoogleCRS(url);
		}
		return crs;
	} catch (final IOException e) {
		return null;
	} finally {
		if (store != null) {
			store.dispose();
		}
	}
}
 
Example 2
Source File: GamaShapeFile.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Envelope3D computeEnvelope(final IScope scope) {
	if (gis == null) {
		ShapefileDataStore store = null;
		try {
			store = getDataStore(getFile(scope).toURI().toURL());
			final Envelope3D env = Envelope3D.of(store.getFeatureSource().getBounds());
			computeProjection(scope, env);
		} catch (final IOException e) {
			return Envelope3D.EMPTY;
		} finally {
			if (store != null) {
				store.dispose();
			}
		}
	}
	return gis.getProjectedEnvelope();

}
 
Example 3
Source File: GamaShapeFile.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
protected void readShapes(final IScope scope) {
	scope.getGui().getStatus(scope).beginSubStatus("Reading file " + getName(scope));
	ShapefileDataStore store = null;
	final File file = getFile(scope);
	final IList list = getBuffer();
	int size = 0;
	try {
		store = getDataStore(file.toURI().toURL());
		final ContentFeatureSource source = store.getFeatureSource();
		final Envelope3D env = Envelope3D.of(source.getBounds());
		size = source.getCount(Query.ALL);
		int index = 0;
		computeProjection(scope, env);
		try (FeatureReader reader = store.getFeatureReader()) {
			while (reader.hasNext()) {
				index++;
				if (index % 20 == 0) {
					scope.getGui().getStatus(scope).setSubStatusCompletion(index / (double) size);
				}
				final Feature feature = reader.next();
				Geometry g = (Geometry) feature.getDefaultGeometryProperty().getValue();
				if (g != null && !g.isEmpty() /* Fix for Issue 725 && 677 */ ) {
					if (!with3D && !g.isValid()) {
						g = GeometryUtils.cleanGeometry(g);
					}
					g = gis.transform(g);
					if (!with3D) {
						g.apply(ZERO_Z);
						g.geometryChanged();
					}
					g = multiPolygonManagement(g);
					GamaGisGeometry gt = new GamaGisGeometry(g, feature);
					if (gt.getInnerGeometry() != null)
						list.add(gt);
					
				} else if (g == null) {
					// See Issue 725
					GAMA.reportError(scope,
							GamaRuntimeException
									.warning("GamaShapeFile.fillBuffer; geometry could not be added  as it is "
											+ "nil: " + feature.getIdentifier(), scope),
							false);
				}
			}
		}
	} catch (final IOException e) {
		throw GamaRuntimeException.create(e, scope);
	} finally {
		if (store != null) {
			store.dispose();
		}
		scope.getGui().getStatus(scope).endSubStatus("Reading file " + getName(scope));
	}
	if (size > list.size()) {
		GAMA.reportError(scope, GamaRuntimeException.warning("Problem with file " + getFile(scope) + ": only "
				+ list.size() + " of the " + size + " geometries could be added", scope), false);
	}
}