Exemplo n.º 1
0
 /**
  * Copy data from Shape File into a new table in specified connection.
  *
  * @param connection Active connection
  * @param tableReference [[catalog.]schema.]table reference
  * @param fileName File path of the SHP file or URI
  * @param forceEncoding Use this encoding instead of DBF file header encoding property.
  */
 public static void readShape(
     Connection connection, String fileName, String tableReference, String forceEncoding)
     throws IOException, SQLException {
   File file = URIUtility.fileFromString(fileName);
   if (!file.exists()) {
     throw new FileNotFoundException("The following file does not exists:\n" + fileName);
   }
   SHPDriverFunction shpDriverFunction = new SHPDriverFunction();
   shpDriverFunction.importFile(
       connection,
       TableLocation.parse(tableReference, true).toString(true),
       file,
       new EmptyProgressVisitor(),
       forceEncoding);
 }
Exemplo n.º 2
0
  private static LayerType createJAXBFromLayer(ILayer layer, MapContext mapContext) {
    ObjectFactory ows_context_factory = new ObjectFactory();
    LayerType layerType = ows_context_factory.createLayerType();
    Description description = layer.getDescription();
    description.initJAXBType(layerType);
    layerType.setHidden(!layer.isVisible());
    ILayer[] childrens = layer.getChildren();
    for (ILayer child : childrens) {
      if (child.isSerializable()) {
        layerType.getLayer().add(createJAXBFromLayer(child, mapContext));
      }
    }
    // If not a Layer Collection
    if (!(layer instanceof LayerCollection) && layer.getStyles() != null) {
      StyleListType slt = ows_context_factory.createStyleListType();
      layerType.setStyleList(slt);
      for (Style style : layer.getStyles()) {
        StyleType st = ows_context_factory.createStyleType();
        slt.getStyle().add(st);
        SLDType sltType = ows_context_factory.createSLDType();
        st.setSLD(sltType);
        sltType.setAbstractStyle(style.getJAXBElement());
      }
    }

    // Serialisation of dataSource as a DataUrl string
    // Create jaxb instances
    URLType dataURL = ows_context_factory.createURLType();
    if (!(layer instanceof LayerCollection)) {
      OnlineResourceType resource = ows_context_factory.createOnlineResourceType();
      dataURL.setOnlineResource(resource);

      String resourceSerialisation = "";
      URI srcUri = layer.getDataUri();
      if (srcUri != null) {
        // If file, use MapContext relative path
        if (srcUri.getScheme().equalsIgnoreCase("file") && mapContext.getLocation() != null) {
          srcUri = URIUtility.relativize(mapContext.getLocation(), srcUri);
        }
        resourceSerialisation = srcUri.toString();
      }
      resource.setHref(resourceSerialisation);
      if (resource.isSetHref()) {
        layerType.setDataURL(dataURL);
      }
    }
    return layerType;
  }
Exemplo n.º 3
0
 /**
  * Copy data from Shape File into a new table in specified connection. The newly created table is
  * given the same name as the filename without the ".shp" extension. If such a table already
  * exists, an exception is thrown.
  *
  * @param connection Active connection
  * @param fileName File path of the SHP file or URI
  */
 public static void readShape(Connection connection, String fileName)
     throws IOException, SQLException {
   final String name = URIUtility.fileFromString(fileName).getName();
   readShape(connection, fileName, name.substring(0, name.lastIndexOf(".")).toUpperCase());
 }