Search in sources :

Example 1 with ClassPathResource

use of com.revolsys.spring.resource.ClassPathResource in project com.revolsys.open by revolsys.

the class TestUtil method doTestGeometry.

public static void doTestGeometry(final Class<?> clazz, final String file) {
    boolean valid = true;
    final Resource resource = new ClassPathResource(file, clazz);
    try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
        int i = 0;
        for (final Record object : reader) {
            final int srid = object.getInteger("srid");
            final int axisCount = object.getInteger("axisCount");
            final double scaleXy = object.getInteger("scaleXy");
            final double scaleZ = object.getInteger("scaleZ");
            final double[] scales = { scaleXy, scaleXy, scaleZ };
            final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
            final String wkt = object.getValue("wkt");
            final Geometry geometry = geometryFactory.geometry(wkt);
            valid &= equalsExpectedWkt(i, object, geometry);
            final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
            GeometryFactory otherGeometryFactory;
            if (coordinateSystem instanceof ProjectedCoordinateSystem) {
                final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
                otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
            } else {
                otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
            }
            final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
            final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
            valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
            i++;
        }
    }
    if (!valid) {
        Assert.fail("Has Errors");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Geometry(com.revolsys.geometry.model.Geometry) Record(com.revolsys.record.Record)

Example 2 with ClassPathResource

use of com.revolsys.spring.resource.ClassPathResource in project com.revolsys.open by revolsys.

the class Fonts method init.

private static void init() {
    synchronized (SYNC) {
        if (!initialized) {
            try {
                final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
                final ClassPathResource resource = new ClassPathResource("com/revolsys/fonts/fontawesome-webfont.ttf");
                final InputStream inputStream = resource.newInputStream();
                final Font font = Font.createFont(Font.TRUETYPE_FONT, inputStream);
                environment.registerFont(font);
            } catch (IOException | FontFormatException e) {
            }
            initialized = true;
        }
    }
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) GraphicsEnvironment(java.awt.GraphicsEnvironment) FontFormatException(java.awt.FontFormatException) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Font(java.awt.Font)

Example 3 with ClassPathResource

use of com.revolsys.spring.resource.ClassPathResource in project com.revolsys.open by revolsys.

the class SvgMarker method postSetMarkerType.

@Override
protected void postSetMarkerType() {
    final String markerType = getMarkerType();
    this.symbol = SymbolLibrary.findSymbol(markerType);
    final Resource resource = new ClassPathResource(markerType + ".svg");
    try {
        final String uri = resource.getUriString();
        this.document = SvgUtil.newDocument(uri);
        this.transcoderInput = new TranscoderInput(this.document);
        this.transcoderInput.setURI(uri);
        this.icon = new SvgIcon(this.document, 16, 16);
    } catch (final Throwable e) {
        this.document = null;
        Logs.error(this, "Cannot open :" + resource, e);
    }
}
Also used : TranscoderInput(org.apache.batik.transcoder.TranscoderInput) ClassPathResource(com.revolsys.spring.resource.ClassPathResource) Resource(com.revolsys.spring.resource.Resource) ClassPathResource(com.revolsys.spring.resource.ClassPathResource)

Example 4 with ClassPathResource

use of com.revolsys.spring.resource.ClassPathResource in project com.revolsys.open by revolsys.

the class SaifReader method loadExportedObjects.

/**
 * Load the exported objects for the SAIF archive.
 *
 * @throws IOException If there was an I/O error.
 */
@SuppressWarnings("unchecked")
private void loadExportedObjects() throws IOException {
    final boolean setNames = this.includeTypeNames.isEmpty();
    final ClassPathResource resource = new ClassPathResource("com/revolsys/io/saif/saifzip.csn");
    final RecordDefinitionFactory schema = new SaifSchemaReader().loadSchema(resource);
    final OsnReader reader = getOsnReader(schema, this.factory, "/exports.dir");
    try {
        final Map<String, String> names = new TreeMap<>();
        if (reader.hasNext()) {
            this.exportedObjects = reader.next();
            final Set<Record> handles = (Set<Record>) this.exportedObjects.getValue("handles");
            for (final Record exportedObject : handles) {
                final String fileName = (String) exportedObject.getValue("objectSubset");
                if (fileName != null && !fileName.equals("globmeta.osn")) {
                    String typePath = getTypeName(fileName);
                    if (typePath == null) {
                        final String name = (String) exportedObject.getValue("type");
                        typePath = PathCache.getName(name);
                        if (!this.fileNameTypeNameMap.containsKey(fileName)) {
                            this.fileNameTypeNameMap.put(fileName, typePath);
                            this.typePathFileNameMap.put(typePath, fileName);
                        }
                    }
                    if (setNames && !fileName.equals("metdat00.osn") && !fileName.equals("refsys00.osn")) {
                        names.put(typePath.toString(), typePath);
                    }
                }
            }
            if (setNames) {
                this.typePaths = new ArrayList<>(names.values());
            } else {
                this.typePaths = new ArrayList<>(this.includeTypeNames);
            }
            this.typePaths.removeAll(this.excludeTypeNames);
        }
    } finally {
        reader.close();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RecordDefinitionFactory(com.revolsys.record.schema.RecordDefinitionFactory) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) TreeMap(java.util.TreeMap) ClassPathResource(com.revolsys.spring.resource.ClassPathResource)

Example 5 with ClassPathResource

use of com.revolsys.spring.resource.ClassPathResource in project com.revolsys.open by revolsys.

the class IntersectionTest method suite.

public static Test suite() {
    final TestSuite suite = new TestSuite("Intersection");
    int index = 0;
    try (MapReader reader = MapReader.newMapReader(new ClassPathResource("/com/revolsys/jts/test/geometry/operation/intersection.tsv"))) {
        for (final MapEx map : reader) {
            index++;
            if (map.getString("active").equalsIgnoreCase("true")) {
                final String description = map.getString("description");
                final int srid = map.getInteger("srid", 0);
                final int axisCount = map.getInteger("axisCount", 2);
                final double scaleXy = map.getDouble("scaleXy", 0.0);
                final double scaleZ = map.getDouble("scaleZ", 0.0);
                final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scaleXy, scaleXy, scaleZ);
                final String geometry1Wkt = map.getString("geometry1");
                final Geometry geometry1 = newGeometry(geometryFactory, geometry1Wkt);
                final String geometry2Wkt = map.getString("geometry2");
                final Geometry geometry2 = newGeometry(geometryFactory, geometry2Wkt);
                final String expectedIntersectionWkt = map.getString("expectedIntersection");
                final Geometry expectedIntersection = newGeometry(geometryFactory, expectedIntersectionWkt);
                final IntersectionTest test = new IntersectionTest(index, description, geometry1, geometry2, expectedIntersection);
                suite.addTest(test);
            }
        }
    }
    return suite;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) TestSuite(junit.framework.TestSuite) MapReader(com.revolsys.io.map.MapReader) MapEx(com.revolsys.collection.map.MapEx) ClassPathResource(com.revolsys.spring.resource.ClassPathResource)

Aggregations

ClassPathResource (com.revolsys.spring.resource.ClassPathResource)6 Geometry (com.revolsys.geometry.model.Geometry)3 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)3 MapReader (com.revolsys.io.map.MapReader)2 Record (com.revolsys.record.Record)2 Resource (com.revolsys.spring.resource.Resource)2 TestSuite (junit.framework.TestSuite)2 MapEx (com.revolsys.collection.map.MapEx)1 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 LineCap (com.revolsys.geometry.model.LineCap)1 LineJoin (com.revolsys.geometry.model.LineJoin)1 BufferParameters (com.revolsys.geometry.operation.buffer.BufferParameters)1 ArrayRecord (com.revolsys.record.ArrayRecord)1 RecordDefinitionFactory (com.revolsys.record.schema.RecordDefinitionFactory)1 Font (java.awt.Font)1 FontFormatException (java.awt.FontFormatException)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1