Beispiel #1
0
 @Override
 public ILayer createLayer(URI source) throws LayerException {
   if (!source.isAbsolute()) {
     // If URI is not absolute ex URI.create("../folder/myfile.shp"), then create a canonical URI
     try {
       source =
           new File(location != null ? new File(location) : new File("./"), source.toString())
               .getCanonicalFile()
               .toURI();
     } catch (IOException ex) {
       throw new LayerException(ex);
     }
   }
   String layerName;
   try {
     layerName = FileUtils.getNameFromURI(source);
   } catch (UnsupportedOperationException ex) {
     try {
       layerName = dataManager.findUniqueTableName(I18N.tr("Layer"));
     } catch (SQLException ex2) {
       throw new LayerException(ex2);
     }
   }
   return createLayer(layerName, source);
 }
Beispiel #2
0
 @Override
 public ILayer createLayer(String layerName, String tableRef) throws LayerException {
   try {
     try (Connection connection = dataManager.getDataSource().getConnection()) {
       List<String> geoFields =
           SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableRef));
       if (!geoFields.isEmpty()) {
         return new Layer(layerName, tableRef, dataManager);
       } else {
         throw new LayerException(I18N.tr("The source contains no spatial info"));
       }
     }
   } catch (SQLException ex) {
     throw new LayerException("Cannot retrieve spatial metadata", ex);
   }
 }