Search in sources :

Example 21 with Resource

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;
}
Also used : GzipResource(com.revolsys.spring.resource.GzipResource) UrlResource(com.revolsys.spring.resource.UrlResource) GzipResource(com.revolsys.spring.resource.GzipResource) UrlResource(com.revolsys.spring.resource.UrlResource) Resource(com.revolsys.spring.resource.Resource)

Example 22 with 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();
    }
}
Also used : Resource(com.revolsys.spring.resource.Resource)

Example 23 with Resource

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);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Resource(com.revolsys.spring.resource.Resource)

Example 24 with Resource

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;
}
Also used : ImageInputStream(javax.imageio.stream.ImageInputStream) InputStream(java.io.InputStream) ImageInputStream(javax.imageio.stream.ImageInputStream) Resource(com.revolsys.spring.resource.Resource) ImageReader(javax.imageio.ImageReader)

Example 25 with Resource

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;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) LinkedHashMapEx(com.revolsys.collection.map.LinkedHashMapEx) MapEx(com.revolsys.collection.map.MapEx) WebServiceResource(com.revolsys.webservice.WebServiceResource) Resource(com.revolsys.spring.resource.Resource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Aggregations

Resource (com.revolsys.spring.resource.Resource)78 PathResource (com.revolsys.spring.resource.PathResource)23 MapEx (com.revolsys.collection.map.MapEx)9 File (java.io.File)9 IOException (java.io.IOException)8 InputStream (java.io.InputStream)6 LinkedHashMapEx (com.revolsys.collection.map.LinkedHashMapEx)5 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 UrlResource (com.revolsys.spring.resource.UrlResource)5 Writer (java.io.Writer)5 Record (com.revolsys.record.Record)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)4 DataType (com.revolsys.datatype.DataType)3 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 Geometry (com.revolsys.geometry.model.Geometry)3 AbstractRecordWriter (com.revolsys.io.AbstractRecordWriter)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 RecordReader (com.revolsys.record.io.RecordReader)3 RecordWriter (com.revolsys.record.io.RecordWriter)3 Blob (java.sql.Blob)3