Search in sources :

Example 1 with Bbox

use of gov.usgs.cida.coastalhazards.model.Bbox in project coastal-hazards by USGS-CIDA.

the class TemplateResource method baseTemplateItem.

private Item baseTemplateItem(boolean active, Bbox bbox, List<Service> serviceCopies, Summary summary) {
    Item baseTemplate = new Item();
    baseTemplate.setType(Type.storms);
    baseTemplate.setRibbonable(true);
    baseTemplate.setShowChildren(true);
    baseTemplate.setName("storm_" + (new SimpleDateFormat("yyyyMMddHHmm").format(Date.from(Instant.now()))));
    baseTemplate.setId(IdGenerator.generate());
    baseTemplate.setItemType(ItemType.template);
    baseTemplate.setActiveStorm(active);
    baseTemplate.setBbox(Bbox.copyValues(bbox, new Bbox()));
    baseTemplate.setServices(serviceCopies);
    baseTemplate.setSummary(summary);
    return baseTemplate;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Bbox

use of gov.usgs.cida.coastalhazards.model.Bbox in project coastal-hazards by USGS-CIDA.

the class ItemManager method calculateBbox.

public Bbox calculateBbox(Item item) {
    Bbox bbox = null;
    if (item != null) {
        if (item.getItemType() == Item.ItemType.data) {
            bbox = item.getBbox();
        } else {
            Query query = em.createNativeQuery("SELECT bbox FROM cch_calc_bbox(:id) as bbox");
            query.setParameter("id", item.getId());
            String singleResult = (String) query.getSingleResult();
            bbox = new Bbox();
            bbox.setBbox(singleResult);
        }
    }
    return bbox;
}
Also used : Query(javax.persistence.Query) Bbox(gov.usgs.cida.coastalhazards.model.Bbox)

Example 3 with Bbox

use of gov.usgs.cida.coastalhazards.model.Bbox in project coastal-hazards by USGS-CIDA.

the class BboxAdapter method deserialize.

@Override
public Bbox deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    Bbox bbox = new Bbox();
    if (json instanceof JsonArray) {
        JsonArray array = (JsonArray) json;
        if (array.size() == 4) {
            double minX = array.get(0).getAsDouble();
            double minY = array.get(1).getAsDouble();
            double maxX = array.get(2).getAsDouble();
            double maxY = array.get(3).getAsDouble();
            bbox.setBbox(minX, minY, maxX, maxY);
        } else if (array.size() == 0) {
            bbox.setBbox(null);
        } else {
            throw new JsonParseException("Bbox must be of format [minX,minY,maxX,maxY]");
        }
    } else {
        throw new JsonParseException("Bbox must be JSON array");
    }
    return bbox;
}
Also used : JsonArray(com.google.gson.JsonArray) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) JsonParseException(com.google.gson.JsonParseException)

Example 4 with Bbox

use of gov.usgs.cida.coastalhazards.model.Bbox in project coastal-hazards by USGS-CIDA.

the class MetadataUtilTest method testGetBoundingBoxFromFgdcMetadataCR.

/**
 * Test of getBoundingBoxFromFgdcMetadataCR method, of class MetadataUtil.
 */
@Test
public void testGetBoundingBoxFromFgdcMetadataCR() throws IOException {
    System.out.println("testGetBoundingBoxFromFgdcMetadataPAE");
    // This method tests the parsing that occurs in: Bbox result = MetadataUtil.getBoundingBoxFromFgdcMetadata(metadata); // file is ~40kb
    // spdom is the WGS84 bbox, format for the Bbox is "BOX(%f %f, %f %f)"
    // get the metadata from the test file as a string using this package to locate it ...
    String packageName = this.getClass().getCanonicalName();
    // PackageName: gov.usgs.cida.coastalhazards.rest.data.util.MetadataUtilTest
    System.out.println("PackageName: " + packageName);
    // this is where the test resource is located - gov.usgs.cida.coastalhazards.rest.data + /ne_AEmeta.xml
    String replaced = packageName.replaceAll("[.]", "/");
    String[] names = replaced.split("/util/MetadataUtilTest");
    String packageNameShort = names[0];
    String testFileFullName = packageNameShort + "/" + CRxml;
    String metadataXml = loadResourceAsString(testFileFullName);
    InputStream in = new ByteArrayInputStream(metadataXml.getBytes("UTF-8"));
    Metadata metadata = null;
    // JAXB will require jaxb-api.jar and jaxb-impl.jar part of java 1.6. Much safer way to interrogate xml and maintain than regex
    try {
        // File file = new File(xmlFile);  // FYI: can also be done via file rather than inputStream
        JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        metadata = (Metadata) jaxbUnmarshaller.unmarshal(in);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    assertNotNull(metadata);
    Idinfo idinfo = metadata.getIdinfo();
    Spdom spdom = idinfo.getSpdom();
    Bounding bounding = spdom.getBounding();
    double minx = bounding.getWestbc();
    double miny = bounding.getSouthbc();
    double maxx = bounding.getEastbc();
    double maxy = bounding.getNorthbc();
    Bbox result = new Bbox();
    result.setBbox(minx, miny, maxx, maxy);
    System.out.println("Parsed Bbox is: " + result.getBbox());
    Bbox expResult = new Bbox();
    expResult.setBbox("BOX(-77.830618 35.344738, -66.813170 46.642941)");
    assertNotNull(result);
    assertTrue(expResult.getBbox().startsWith("BOX(-77.830618 35."));
    assertTrue(expResult.getBbox().equalsIgnoreCase(result.getBbox()));
}
Also used : Bounding(gov.usgs.cida.coastalhazards.xml.model.Bounding) Spdom(gov.usgs.cida.coastalhazards.xml.model.Spdom) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) Metadata(gov.usgs.cida.coastalhazards.xml.model.Metadata) JAXBContext(javax.xml.bind.JAXBContext) Idinfo(gov.usgs.cida.coastalhazards.xml.model.Idinfo) ByteArrayInputStream(java.io.ByteArrayInputStream) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 5 with Bbox

use of gov.usgs.cida.coastalhazards.model.Bbox in project coastal-hazards by USGS-CIDA.

the class MetadataUtilTest method testGetBoundingBoxFromFgdcMetadataAE.

/**
 * Test of getBoundingBoxFromFgdcMetadataAE method, of class MetadataUtil.
 */
@Test
public void testGetBoundingBoxFromFgdcMetadataAE() throws IOException {
    System.out.println("testGetBoundingBoxFromFgdcMetadataAE");
    // This method tests the parsing that occurs in: Bbox result = MetadataUtil.getBoundingBoxFromFgdcMetadata(metadata); // file is ~40kb
    // spdom is the WGS84 bbox, format for the Bbox is "BOX(%f %f, %f %f)"
    // get the metadata from the test file as a string using this package to locate it ...
    String packageName = this.getClass().getCanonicalName();
    // PackageName: gov.usgs.cida.coastalhazards.rest.data.util.MetadataUtilTest
    System.out.println("PackageName: " + packageName);
    // this is where the test resource is located - gov.usgs.cida.coastalhazards.rest.data + /ne_AEmeta.xml
    String replaced = packageName.replaceAll("[.]", "/");
    String[] names = replaced.split("/util/MetadataUtilTest");
    String packageNameShort = names[0];
    String testFileFullName = packageNameShort + "/" + AExml;
    String metadataXml = loadResourceAsString(testFileFullName);
    InputStream in = new ByteArrayInputStream(metadataXml.getBytes("UTF-8"));
    Metadata metadata = null;
    // JAXB will require jaxb-api.jar and jaxb-impl.jar part of java 1.6. Much safer way to interrogate xml and maintain than regex
    try {
        // File file = new File(xmlFile);  // FYI: can also be done via file rather than inputStream
        JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        metadata = (Metadata) jaxbUnmarshaller.unmarshal(in);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    assertNotNull(metadata);
    Idinfo idinfo = metadata.getIdinfo();
    Spdom spdom = idinfo.getSpdom();
    Bounding bounding = spdom.getBounding();
    double minx = bounding.getWestbc();
    double miny = bounding.getSouthbc();
    double maxx = bounding.getEastbc();
    double maxy = bounding.getNorthbc();
    Bbox result = new Bbox();
    result.setBbox(minx, miny, maxx, maxy);
    System.out.println("Parsed Bbox is: " + result.getBbox());
    Bbox expResult = new Bbox();
    expResult.setBbox("BOX(-77.830618 35.344738, -66.813170 46.642941)");
    assertNotNull(result);
    assertTrue(expResult.getBbox().startsWith("BOX(-77.830618 35."));
    assertTrue(expResult.getBbox().equalsIgnoreCase(result.getBbox()));
}
Also used : Bounding(gov.usgs.cida.coastalhazards.xml.model.Bounding) Spdom(gov.usgs.cida.coastalhazards.xml.model.Spdom) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) Metadata(gov.usgs.cida.coastalhazards.xml.model.Metadata) JAXBContext(javax.xml.bind.JAXBContext) Idinfo(gov.usgs.cida.coastalhazards.xml.model.Idinfo) ByteArrayInputStream(java.io.ByteArrayInputStream) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Aggregations

Bbox (gov.usgs.cida.coastalhazards.model.Bbox)12 ByteArrayInputStream (java.io.ByteArrayInputStream)4 JAXBException (javax.xml.bind.JAXBException)4 Test (org.junit.Test)4 Service (gov.usgs.cida.coastalhazards.model.Service)3 WFSService (gov.usgs.cida.coastalhazards.util.ogc.WFSService)3 Bounding (gov.usgs.cida.coastalhazards.xml.model.Bounding)3 Idinfo (gov.usgs.cida.coastalhazards.xml.model.Idinfo)3 Metadata (gov.usgs.cida.coastalhazards.xml.model.Metadata)3 Spdom (gov.usgs.cida.coastalhazards.xml.model.Spdom)3 JAXBContext (javax.xml.bind.JAXBContext)3 Unmarshaller (javax.xml.bind.Unmarshaller)3 JsonArray (com.google.gson.JsonArray)2 LayerManager (gov.usgs.cida.coastalhazards.jpa.LayerManager)2 Item (gov.usgs.cida.coastalhazards.model.Item)2 Layer (gov.usgs.cida.coastalhazards.model.Layer)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 RolesAllowed (javax.annotation.security.RolesAllowed)2 Consumes (javax.ws.rs.Consumes)2