Search in sources :

Example 11 with Bbox

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

the class TemplateResource method templateItem.

private Item templateItem(Item template, String attr, Layer layer, Summary summary) {
    String newId = IdGenerator.generate();
    Item newItem = new Item();
    newItem.setAttr(attr);
    boolean isRibbonable = Attributes.getRibbonableAttrs().contains(attr);
    List<Service> services = layer.getServices();
    Bbox bbox = layer.getBbox();
    List<Service> serviceCopies = new LinkedList<>();
    for (Service service : services) {
        serviceCopies.add(Service.copyValues(service, null));
    }
    newItem.setServices(serviceCopies);
    newItem.setItemType(Item.ItemType.data);
    newItem.setSummary(summary);
    newItem.setId(newId);
    newItem.setBbox(Bbox.copyValues(bbox, new Bbox()));
    newItem.setActiveStorm(template.isActiveStorm());
    newItem.setRibbonable(isRibbonable);
    newItem.setType(template.getType());
    newItem.setName(template.getName());
    return newItem;
}
Also used : Item(gov.usgs.cida.coastalhazards.model.Item) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) WFSService(gov.usgs.cida.coastalhazards.util.ogc.WFSService) OGCService(gov.usgs.cida.coastalhazards.util.ogc.OGCService) Service(gov.usgs.cida.coastalhazards.model.Service) LinkedList(java.util.LinkedList)

Example 12 with Bbox

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

the class MetadataUtil method getBoundingBoxFromFgdcMetadata.

public static Bbox getBoundingBoxFromFgdcMetadata(String inMetadata) throws JAXBException, UnsupportedEncodingException {
    Bbox bbox = new Bbox();
    // parse out the WGS84 bbox from the metadata xml
    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 {
        JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        metadata = (Metadata) jaxbUnmarshaller.unmarshal(new ByteArrayInputStream(inMetadata.getBytes("UTF-8")));
    } catch (JAXBException e) {
        // schema used https: www.fgdc.gov/schemas/metadata/fgdc-std-001-1998-sect01.xsd
        log.error("Unable to parse xml file. Has the schema changed? https://www.fgdc.gov/schemas/metadata/fgdc-std-001-1998-sect01.xsd :" + e.getMessage());
        throw e;
    }
    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);
    bbox.setBbox(minx, miny, maxx, maxy);
    return bbox;
}
Also used : Bounding(gov.usgs.cida.coastalhazards.xml.model.Bounding) Spdom(gov.usgs.cida.coastalhazards.xml.model.Spdom) ByteArrayInputStream(java.io.ByteArrayInputStream) Bbox(gov.usgs.cida.coastalhazards.model.Bbox) JAXBException(javax.xml.bind.JAXBException) Metadata(gov.usgs.cida.coastalhazards.xml.model.Metadata) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) Idinfo(gov.usgs.cida.coastalhazards.xml.model.Idinfo)

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