use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class IoFactory method getZipResource.
default Resource getZipResource(final Object source) {
Resource resource = Resource.getResource(source);
if (isReadFromZipFileSupported()) {
final String filename = resource.getFilename();
if (filename.endsWith(".zip")) {
final String baseName = filename.substring(0, filename.length() - 4);
final String url = "jar:" + resource.getUri() + "!/" + baseName;
final UrlResource urlResource = new UrlResource(url);
if (urlResource.exists()) {
resource = urlResource;
} else {
return null;
}
} else if (filename.endsWith(".gz")) {
return new GzipResource(resource);
} else if (filename.endsWith(getFileExtensions().get(0) + "z")) {
return new GzipResource(resource);
}
}
return resource;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method loadWorldFileX.
protected void loadWorldFileX() {
final Resource resource = getImageResource();
final Resource worldFile = resource.newResourceChangeExtension(getWorldFileExtension() + "x");
if (worldFile.exists()) {
loadWorldFile(worldFile);
} else {
loadWorldFile();
}
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method loadProjectionFile.
protected void loadProjectionFile() {
final Resource resource = getImageResource();
final GeometryFactory geometryFactory = GeometryFactory.floating2d(resource);
setGeometryFactory(geometryFactory);
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class AbstractGeoreferencedImage method getDpi.
@Override
public int[] getDpi() {
if (this.dpi == null) {
int[] dpi = new int[] { 96, 96 };
try {
final Resource imageResource = getImageResource();
final InputStream in = imageResource.getInputStream();
final ImageInputStream iis = ImageIO.createImageInputStream(in);
final Iterator<ImageReader> i = ImageIO.getImageReaders(iis);
if (i.hasNext()) {
final ImageReader r = i.next();
r.setInput(iis);
dpi = getResolution(r);
if (dpi[0] == 0) {
dpi[0] = 96;
}
if (dpi[1] == 0) {
dpi[1] = 96;
}
r.dispose();
}
iis.close();
} catch (final Throwable e) {
e.printStackTrace();
}
this.dpi = dpi;
}
return this.dpi;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class FeatureSource method newLayer.
private FeatureLayer newLayer(final String name, final MapEx element, final MapEx complexType) {
if (!"true".equals(getString(complexType, "@abstract"))) {
final PathName pathName = getPathName();
final PathName layerPathName = pathName.newChild(name);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(layerPathName);
GeometryFactory geometryFactory = GeometryFactory.DEFAULT_3D;
final MapEx complexContent = getValue(complexType, "xs:complexContent");
final MapEx extension = getValue(complexContent, "xs:extension");
if ("gml:AbstractFeatureType".equals(getString(extension, "@base"))) {
final MapEx sequence = getValue(extension, "xs:sequence");
final List<MapEx> elements = sequence.getValue("xs:element");
for (final MapEx fieldElement : elements) {
final String fieldName = getString(fieldElement, "@name");
final boolean required = !"0".equals(getString(fieldElement, "@minOccurs"));
DataType dataType = DataTypes.STRING;
final MapEx simpleFieldType = getValue(fieldElement, "xs:simpleType");
if (simpleFieldType == null) {
final String fieldType = getString(fieldElement, "@type");
if ("gml:AbstractGeometryType".equals(fieldType)) {
final String geometryTypes = getString(fieldElement, "@fdo:geometryTypes");
for (final String geometryType : geometryTypes.split(" ")) {
final DataType geometryDataType = DataTypes.getDataType(geometryType);
if (geometryDataType != DataTypes.OBJECT) {
if (dataType == DataTypes.STRING) {
dataType = geometryDataType;
} else if (dataType == DataTypes.GEOMETRY) {
} else if (geometryDataType == DataTypes.GEOMETRY) {
dataType = DataTypes.GEOMETRY;
} else if (geometryDataType == DataTypes.GEOMETRY_COLLECTION) {
dataType = DataTypes.GEOMETRY;
} else if (dataType.equals(DataTypes.POINT)) {
if (geometryDataType.equals(DataTypes.POINT)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
dataType = DataTypes.MULTI_POINT;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_POINT)) {
if (geometryDataType.equals(DataTypes.POINT)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POINT)) {
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.LINE_STRING)) {
if (geometryDataType.equals(DataTypes.LINE_STRING)) {
} else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
dataType = DataTypes.MULTI_LINE_STRING;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_LINE_STRING)) {
if (geometryDataType.equals(DataTypes.LINE_STRING)) {
} else if (geometryDataType.equals(DataTypes.MULTI_LINE_STRING)) {
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.POLYGON)) {
if (geometryDataType.equals(DataTypes.POLYGON)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
dataType = DataTypes.MULTI_POLYGON;
} else {
dataType = DataTypes.GEOMETRY;
}
} else if (dataType.equals(DataTypes.MULTI_POLYGON)) {
if (geometryDataType.equals(DataTypes.POLYGON)) {
} else if (geometryDataType.equals(DataTypes.MULTI_POLYGON)) {
} else {
dataType = DataTypes.GEOMETRY;
}
}
}
}
if (dataType == DataTypes.STRING) {
dataType = DataTypes.GEOMETRY;
}
int axisCount = 2;
if ("true".equals(getString(fieldElement, "@fdo:hasMeasure"))) {
axisCount = 4;
} else if ("true".equals(getString(fieldElement, "@fdo:hasElevation"))) {
axisCount = 3;
}
final String srsName = getString(fieldElement, "@fdo:srsName");
if (Property.hasValue(srsName)) {
final Integer coordinateSystemId = Maps.getInteger(this.coordinateSystemIdBySrsName, srsName);
if (coordinateSystemId == null) {
try {
final Map<String, Object> csParameters = Collections.singletonMap("CSCODE", srsName);
final MapGuideWebService webService = getWebService();
final Resource wktResource = webService.getResource("CS.CONVERTCOORDINATESYSTEMCODETOWKT", null, csParameters);
final String wkt = wktResource.contentsAsString();
geometryFactory = GeometryFactory.floating(wkt, axisCount);
} catch (final Throwable e) {
}
} else {
geometryFactory = GeometryFactory.floating(coordinateSystemId, axisCount);
}
}
}
} else {
final MapEx restriction = getValue(simpleFieldType, "xs:restriction");
if (restriction != null) {
final String fieldBase = getString(restriction, "@base");
dataType = DataTypes.getDataType(fieldBase.replace("xs:", ""));
}
}
if (dataType != null) {
recordDefinition.addField(fieldName, dataType, required);
}
}
recordDefinition.setGeometryFactory(geometryFactory);
final FeatureLayer layer = new FeatureLayer(this, recordDefinition);
return layer;
}
}
return null;
}
Aggregations