/**
  * Populates the names array with the names of legends that can be applied to the given layer.
  *
  * @param layer Layer
  */
 private void initNamesList(ILayer layer) {
   // Recover the geometry type of this ILayer.
   DataSource ds = layer.getDataManager().getDataSource();
   int geometryColumnsCount = 0;
   int geomType = GeometryTypeCodes.GEOMETRY;
   try (Connection connection = ds.getConnection()) {
     TableLocation tableLocation = TableLocation.parse(layer.getTableReference());
     geomType = SFSUtilities.getGeometryType(connection, tableLocation, "");
     geometryColumnsCount = SFSUtilities.getGeometryFields(connection, tableLocation).size();
   } catch (SQLException e) {
     LOGGER.warn("Could not determine the specific geometry type for " + "this layer.");
   }
   // Convert to a simple geometry.
   int simpleGeomType = SimpleGeometryType.getSimpleType(geomType);
   // Fill the names array.
   ArrayList<String> typeNames = new ArrayList<>();
   final int lineOrPolygon = SimpleGeometryType.LINE | SimpleGeometryType.POLYGON;
   if ((simpleGeomType & SimpleGeometryType.ALL) != 0) {
     typeNames.add(UniqueSymbolPoint.NAME);
     if ((simpleGeomType & lineOrPolygon) != 0) {
       typeNames.add(UniqueSymbolLine.NAME);
     }
     if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
       typeNames.add(UniqueSymbolArea.NAME);
     }
     // Do not display the thematic maps that need an attribute if there is
     // only one geometry
     if (geometryColumnsCount > -1) {
       typeNames.add(RecodedPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(RecodedLine.NAME);
       }
       if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
         typeNames.add(RecodedArea.NAME);
       }
       typeNames.add(ProportionalPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(ProportionalLine.NAME);
       }
       typeNames.add(CategorizedPoint.NAME);
       if ((simpleGeomType & lineOrPolygon) != 0) {
         typeNames.add(CategorizedLine.NAME);
       }
       if ((simpleGeomType & SimpleGeometryType.POLYGON) != 0) {
         typeNames.add(CategorizedArea.NAME);
       }
     }
   }
   names = typeNames.toArray(new String[typeNames.size()]);
 }
Exemple #2
0
 /**
  * Return the first spatial geometry field name
  *
  * @param tableName
  * @param connection
  * @return the name of the first geometry column
  * @throws SQLException
  */
 private static String getFirstGeometryField(String tableName, Connection connection)
     throws SQLException {
   // Find first geometry column
   List<String> geomFields =
       SFSUtilities.getGeometryFields(
           connection,
           TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData())));
   if (!geomFields.isEmpty()) {
     return geomFields.get(0);
   } else {
     throw new SQLException("The table " + tableName + " does not contain a geometry field");
   }
 }
Exemple #3
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);
   }
 }