org.geotools.data.FeatureSource Java Examples
The following examples show how to use
org.geotools.data.FeatureSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShapeFileParser.java From GeoTriples with Apache License 2.0 | 6 votes |
public List<GeneralResultRow> getData(String tablename) throws Exception { if (cacheList.containsKey(tablename)) { return cacheList.get(tablename); } else if (cacheList.containsKey(tablename.replaceAll("_geometry", ""))) { return cacheList.get(tablename.replaceAll("_geometry", "")); } DataStore dataStore = null; List<GeneralResultRow> result = null; try { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", shapefile.toURI().toURL()); dataStore = DataStoreFinder.getDataStore(connect); FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(tablename .replaceAll("_geometry", "")); if (featureSource != null) { result = getData(featureSource); } } catch (Exception ex) { ex.printStackTrace(); } finally { dataStore.dispose(); } cacheList.put(tablename.replaceAll("_geometry", ""), result); return result; }
Example #2
Source File: ShpConnector.java From TripleGeo with GNU General Public License v3.0 | 6 votes |
/** * Loads the shape file from the configuration path and returns the * feature collection associated according to the configuration. * * @param shapePath with the path to the shapefile. * @param featureString with the featureString to filter. * * @return FeatureCollection with the collection of features filtered. */ private FeatureCollection getShapeFileFeatureCollection(String shapePath, String featureString) throws IOException { File file = new File(shapePath); // Create the map with the file URL to be passed to DataStore. Map map = new HashMap(); try { map.put("url", file.toURL()); } catch (MalformedURLException ex) { Logger.getLogger(ShpConnector.class.getName()).log(Level.SEVERE, null, ex); } if (map.size() > 0) { DataStore dataStore = DataStoreFinder.getDataStore(map); FeatureSource featureSource = dataStore.getFeatureSource(featureString); return featureSource.getFeatures(); } return null; }
Example #3
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Render vector symbol. * * @param mapContent the map content * @param styledLayer the styled layer * @param style the style */ private void renderVectorSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) { FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null; if (styledLayer instanceof UserLayer) { if (userLayerFeatureListMap != null) { tmpFeatureList = userLayerFeatureListMap.get(styledLayer); } } else { tmpFeatureList = featureList; } if (tmpFeatureList != null) { mapContent.addLayer( new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style)); try { mapPane.setDisplayArea(tmpFeatureList.getBounds()); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } } }
Example #4
Source File: FeatureFigureEditorApp.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected void loadFigureCollection(File file, FigureCollection figureCollection) throws IOException { FeatureSource<SimpleFeatureType, SimpleFeature> featureFeatureSource; FeatureCollection<SimpleFeatureType, SimpleFeature> featureTypeSimpleFeatureFeatureCollection; featureFeatureSource = getFeatureSource(file); featureTypeSimpleFeatureFeatureCollection = featureFeatureSource.getFeatures(); try(FeatureIterator<SimpleFeature> featureIterator = featureTypeSimpleFeatureFeatureCollection.features();) { while (featureIterator.hasNext()) { SimpleFeature simpleFeature = featureIterator.next(); DefaultFigureStyle figureStyle = createDefaultFigureStyle(); Object o = simpleFeature.getDefaultGeometry(); if (o instanceof Point) { figureCollection.addFigure(new SimpleFeaturePointFigure(simpleFeature, sceneTransformProvider, figureStyle)); } else { figureCollection.addFigure(new SimpleFeatureShapeFigure(simpleFeature, sceneTransformProvider, figureStyle)); } } } }
Example #5
Source File: ExtractValidFieldTypes.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Process styles. * * @param fieldsUpdated the fields updated * @param styleList the style list * @param featureList the feature list * @return true, if successful */ private static boolean processStyles( boolean fieldsUpdated, List<org.geotools.styling.Style> styleList, FeatureSource<SimpleFeatureType, SimpleFeature> featureList) { for (Style style : styleList) { for (FeatureTypeStyle fts : style.featureTypeStyles()) { for (Rule rule : fts.rules()) { Object drawMe = null; try { drawMe = featureList.getFeatures().features().next(); } catch (IOException | NoSuchElementException e) { ConsoleManager.getInstance().exception(ExtractValidFieldTypes.class, e); } fieldsUpdated = processRule(fieldsUpdated, rule, drawMe); } } } return fieldsUpdated; }
Example #6
Source File: ExtractValidFieldTypes.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Evaluate fields types. * * @return true, field types updated */ public static boolean fieldTypesUpdated() { boolean fieldsUpdated = false; StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld(); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<org.geotools.styling.Style> styleList = SLDUtils.getStylesList(styledLayer); FeatureSource<SimpleFeatureType, SimpleFeature> featureList = DataSourceFactory.getDataSource().getFeatureSource(); if (featureList != null) { fieldsUpdated = processStyles(fieldsUpdated, styleList, featureList); } } } return fieldsUpdated; }
Example #7
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the feature store. * * @return the feature store */ public FeatureStore<SimpleFeatureType, SimpleFeature> getFeatureStore() { FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = null; if (dataStore != null) { try { FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName); featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource; } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } } return featureStore; }
Example #8
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override public Envelope getBounds(Filter filter) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } try { FeatureCollection<SimpleFeatureType, SimpleFeature> fc; if (null == filter) { fc = source.getFeatures(); } else { fc = source.getFeatures(filter); } FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return fc.getBounds(); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }
Example #9
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * {@inheritDoc} * */ @Transactional(readOnly = true) public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); try { if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } Query query = new Query(); query.setFilter(filter); query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE); query.setStartIndex(offset); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query); FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return new JavaIterator(it); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }
Example #10
Source File: GeoToolsFeatureModelTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Before public void init() throws Exception { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); URL url = classloader.getResource(SHAPE_FILE); DataStore dataStore = new ShapefileDataStore(url); featureModel = new GeoToolsFeatureModel(dataStore, LAYER_NAME, 4326, converterService); featureModel.setLayerInfo(layerInfo); FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureModel.getFeatureSource(); FeatureIterator<SimpleFeature> fi = fs.getFeatures().features(); feature = fi.next(); feature = fi.next(); feature = fi.next(); feature = fi.next(); feature = fi.next(); }
Example #11
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the feature store. * * @return the feature store */ public FeatureStore<SimpleFeatureType, SimpleFeature> getFeatureStore() { FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = null; if(dataStore != null) { try { FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName); featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) featureSource; } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } } return featureStore; }
Example #12
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Gets the features. * * @return the features */ public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatures() { FeatureSource<SimpleFeatureType, SimpleFeature> features = null; try { if((schema != null) && (dataStore != null)) { features = dataStore.getFeatureSource(schema.getName()); } }catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } return features; }
Example #13
Source File: ShapeInMemFeatureModelTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Before public void setUp() throws Exception { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); URL url = classloader.getResource(SHAPE_FILE); DataStore dataStore = new ShapefileDataStore(url); featureModel = new ShapeInMemFeatureModel(dataStore, LAYER_NAME, 4326, converterService); featureModel.setLayerInfo(layerInfo); FeatureSource<SimpleFeatureType, SimpleFeature> fs = featureModel.getFeatureSource(); FeatureIterator<SimpleFeature> fi = fs.getFeatures().features(); feature = fi.next(); feature = fi.next(); feature = fi.next(); feature = fi.next(); feature = fi.next(); fi.close(); }
Example #14
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override // CHECKSTYLE:OFF public Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() { // CHECKSTYLE:ON Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> map = new HashMap<>(); for (DataSourceInfo dsInfo : userLayerDataSourceInfo) { FeatureSource<SimpleFeatureType, SimpleFeature> features = dsInfo.getFeatures(); UserLayer userLayer = dsInfo.getUserLayer(); map.put(userLayer, features); } return map; }
Example #15
Source File: FieldConfigDSPropertiesTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override // CHECKSTYLE:OFF public Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() { // CHECKSTYLE:ON return null; }
Example #16
Source File: FieldConfigGeometryFieldTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override // CHECKSTYLE:OFF public Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() { // CHECKSTYLE:ON return null; }
Example #17
Source File: DataSourceImplTest.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. */ @Test public void testConnectToInlineDataSource() { DataSourceImpl ds = new DataSourceImpl(); DummyInlineSLDFile editorFile = new DummyInlineSLDFile(); DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate(); ds.addListener(dataSourceUpdateListener); CreateDataSourceInterface internalDataSource = new DummyCreateDataSource(); CreateDataSourceInterface externalDataSource = new DummyCreateDataSource(); CreateDataSourceInterface inlineDataSource = new CreateInlineDataSource(); ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource); ds.connect("typeName", editorFile, null); assertTrue(dataSourceUpdateListener.hasBeenCalled()); assertEquals(GeometryTypeEnum.UNKNOWN, dataSourceUpdateListener.geometryType); assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag); Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList(); assertNull(fieldList); FeatureSource<SimpleFeatureType, SimpleFeature> exampleLayer = ds.getExampleFeatureSource(); assertNull(exampleLayer); Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> userLayerMap = ds.getUserLayerFeatureSource(); assertEquals(1, userLayerMap.size()); assertFalse(dataSourceUpdateListener.hasBeenCalled()); ds.updateUserLayers(); assertTrue(dataSourceUpdateListener.hasBeenCalled()); DataSourcePropertiesInterface dsi = ds.getDataConnectorProperties(); assertNotNull(dsi); }
Example #18
Source File: ShapefileAssistantPage1.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public AbstractLayerSourceAssistantPage getNextPage() { final LayerSourcePageContext context = getContext(); fileHistoryModel.getHistory().copyInto(SnapApp.getDefault().getPreferences()); String path = (String) fileHistoryModel.getSelectedItem(); if (path != null && !path.trim().isEmpty()) { try { final String oldPath = (String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH); if (!path.equals(oldPath)) { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH, path); final URL fileUrl = new File(path).toURI().toURL(); final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = FeatureUtils.getFeatureSource(fileUrl); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION, featureSource.getFeatures()); // clear other properties they are not valid anymore context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, null); } FeatureCollection fc = (FeatureCollection) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION); final CoordinateReferenceSystem featureCrs = fc.getSchema().getCoordinateReferenceSystem(); if (featureCrs == null) { return new ShapefileAssistantPage2(); } else { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, featureCrs); return new ShapefileAssistantPage3(); } } catch (Exception e) { e.printStackTrace(); context.showErrorDialog("Failed to load ESRI shapefile:\n" + e.getMessage()); } } return null; }
Example #19
Source File: FeatureFigureEditorApp.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource(File file) throws IOException { Map<String, Object> map = new HashMap<String, Object>(); map.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL()); map.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE); DataStore shapefileStore = DataStoreFinder.getDataStore(map); String typeName = shapefileStore.getTypeNames()[0]; // Shape files do only have one type name FeatureSource<SimpleFeatureType, SimpleFeature> featureSource; featureSource = shapefileStore.getFeatureSource(typeName); return featureSource; }
Example #20
Source File: RenderPanelImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Render vector map. * * @param features the results * @param imageSize the image size * @param style the style * @param dpi the dpi */ private void renderVectorMap( FeatureSource<SimpleFeatureType, SimpleFeature> features, Rectangle imageSize, Style style, int dpi) { List<Layer> layerList = new ArrayList<>(); if (style != null) { FeatureLayer featureLayer = new FeatureLayer(features, style); layerList.add(featureLayer); } boolean hasGeometry = false; ReferencedEnvelope bounds = null; if (features != null) { bounds = calculateBounds(); wmsEnvVarValues.setMapBounds(bounds); EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues); if (features.getSchema() != null) { hasGeometry = (features.getSchema().getGeometryDescriptor() != null); } } internalRenderMap(layerList, bounds, imageSize, hasGeometry, dpi); }
Example #21
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the example feature source. * * @return the example feature source */ /* * (non-Javadoc) * * @see com.sldeditor.datasource.impl.DataSourceInterface#getExampleFeatureSource() */ @Override public FeatureSource<SimpleFeatureType, SimpleFeature> getExampleFeatureSource() { if (exampleDataSourceInfo != null) { return exampleDataSourceInfo.getFeatures(); } return null; }
Example #22
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the feature source. * * @return the feature source */ /* * (non-Javadoc) * * @see com.sldeditor.datasource.impl.DataSourceInterface#getFeatureSource() */ @Override public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() { return dataSourceInfo.getFeatures(); }
Example #23
Source File: DataSourceInfo.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the features. * * @return the features */ public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatures() { FeatureSource<SimpleFeatureType, SimpleFeature> features = null; try { if ((schema != null) && (dataStore != null)) { features = dataStore.getFeatureSource(schema.getName()); } } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } return features; }
Example #24
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the example feature source. * * @return the example feature source */ /* (non-Javadoc) * @see com.sldeditor.datasource.impl.DataSourceInterface#getExampleFeatureSource() */ @Override public FeatureSource<SimpleFeatureType, SimpleFeature> getExampleFeatureSource() { FeatureSource<SimpleFeatureType, SimpleFeature> features = exampleDataSourceInfo.getFeatures(); return features; }
Example #25
Source File: DataSourceImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Gets the feature source. * * @return the feature source */ /* (non-Javadoc) * @see com.sldeditor.datasource.impl.DataSourceInterface#getFeatureSource() */ @Override public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() { FeatureSource<SimpleFeatureType, SimpleFeature> features = dataSourceInfo.getFeatures(); return features; }
Example #26
Source File: DataSourceImplTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** Test method for {@link com.sldeditor.datasource.impl.DataSourceImpl#connect()}. */ @Test public void testConnectToExternalDataSource() { DataSourceImpl ds = new DataSourceImpl(); DummyExternalSLDFile editorFile = new DummyExternalSLDFile(); DummyDataSourceUpdate dataSourceUpdateListener = new DummyDataSourceUpdate(); ds.addListener(dataSourceUpdateListener); CreateDataSourceInterface internalDataSource = new DummyCreateDataSource(); CreateDataSourceInterface externalDataSource = new CreateExternalDataSource(); CreateDataSourceInterface inlineDataSource = new DummyCreateDataSource(); ds.setDataSourceCreation(internalDataSource, externalDataSource, inlineDataSource); ds.connect(editorFile.getTypeName(), editorFile, null); assertEquals(GeometryTypeEnum.POINT, dataSourceUpdateListener.geometryType); assertTrue(dataSourceUpdateListener.isConnectedToDataSourceFlag); Collection<PropertyDescriptor> fieldList = ds.getPropertyDescriptorList(); assertTrue(fieldList != null); List<String> actualFieldnameList = new ArrayList<String>(); for (PropertyDescriptor field : fieldList) { actualFieldnameList.add(field.getName().getLocalPart()); } // Check fields extracted ok List<String> expectedFieldList = editorFile.getExpectedFieldList(); assertTrue(expectedFieldList.size() == actualFieldnameList.size()); // Not assuming fields are in the same order int count = 0; for (String fieldName : actualFieldnameList) { if (expectedFieldList.contains(fieldName)) { count++; } } assertTrue(expectedFieldList.size() == count); // Check for fields of certain types assertEquals(1, ds.getAttributes(Integer.class).size()); assertEquals(1, ds.getAttributes(Long.class).size()); assertEquals(1, ds.getAttributes(Double.class).size()); assertEquals(1, ds.getAttributes(String.class).size()); // Add new field - shouldn't work because connections to external data sources are fixed DataSourceAttributeData dataSourceField = new DataSourceAttributeData("bearing", Double.class, null); ds.addField(dataSourceField); assertTrue(ds.getAttributes(Double.class).size() == 1); // Update field DataSourceAttributeList attributeData = new DataSourceAttributeList(); ds.readAttributes(attributeData); assertTrue(ds.getPropertyDescriptorList().size() == attributeData.getData().size()); List<DataSourceAttributeData> attributeDataList = attributeData.getData(); DataSourceAttributeData data = attributeDataList.remove(2); data.setType(Integer.class); attributeDataList.add(2, data); // Update fields - shouldn't work because connections to external data sources are fixed ds.updateFields(attributeData); assertTrue(ds.getAttributes(Integer.class).size() == 1); FeatureSource<SimpleFeatureType, SimpleFeature> features = ds.getFeatureSource(); try { assertTrue(features.getFeatures().size() > 1); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage()); } assertFalse(dataSourceUpdateListener.isConnectedToDataSourceFlag); }
Example #27
Source File: ShapeFileParserGDAL.java From GeoTriples with Apache License 2.0 | 4 votes |
public List<TableDef> getTablesDefs() throws Exception { DataStore dataStore = null; List<ColumnDef> columns = null; TableDef onlytable = null; Set<Key> primkeys = new HashSet<Key>(); List<TableDef> tables = new ArrayList<TableDef>(); try { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", shapefile.toURI().toURL()); dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); columns = new ArrayList<ColumnDef>(); for (PropertyDescriptor property : ft.getDescriptors()) { Identifier identifier = Identifier.createDelimited(property.getName().getLocalPart()); DataType datatype = TableDefUtils .TranslateDataTypeToSQLType((property.getType().getBinding().getName())); ColumnDef col = new ColumnDef(identifier, datatype, property.isNillable()); columns.add(col); } // Identifier identifier = Identifier.createDelimited("gid"); // ColumnDef col = new ColumnDef(identifier, // TranslateDataTypeToSQLType("Int"), false); // columns.add(col); // primkeys.add(Key.create(identifier)); TableName tablename = TableName.create(null, null, Identifier.create(true, dataStore.getTypeNames()[0])); onlytable = new TableDef(tablename, columns, null, primkeys, new HashSet<ForeignKey>()); tables.add(onlytable); } } catch (Throwable e) { throw new Exception(e.getMessage()); } finally { dataStore.dispose(); } return tables; }
Example #28
Source File: ShapeFileParser.java From GeoTriples with Apache License 2.0 | 4 votes |
public List<TableDef> getTablesDefs() throws Exception { DataStore dataStore = null; List<ColumnDef> columns = null; TableDef onlytable = null; Set<Key> primkeys = new HashSet<Key>(); List<TableDef> tables = new ArrayList<TableDef>(); try { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", shapefile.toURI().toURL()); dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; FeatureSource<?, ?> featureSource = dataStore .getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); columns = new ArrayList<ColumnDef>(); for (PropertyDescriptor property : ft.getDescriptors()) { Identifier identifier = Identifier.createDelimited(property .getName().getLocalPart()); DataType datatype = TableDefUtils.TranslateDataTypeToSQLType((property .getType().getBinding().getName())); ColumnDef col = new ColumnDef(identifier, datatype, property.isNillable()); columns.add(col); } //Identifier identifier = Identifier.createDelimited("gid"); //ColumnDef col = new ColumnDef(identifier, TranslateDataTypeToSQLType("Int"), false); //columns.add(col); //primkeys.add(Key.create(identifier)); TableName tablename = TableName.create(null, null, Identifier.create(true, dataStore.getTypeNames()[0])); onlytable = new TableDef(tablename, columns, null, primkeys, new HashSet<ForeignKey>()); tables.add(onlytable); } } catch (Throwable e) { throw new Exception(e.getMessage()); } finally { dataStore.dispose(); } return tables; }
Example #29
Source File: ShapefileMappingGenerator.java From GeoTriples with Apache License 2.0 | 4 votes |
public void run() throws IOException { Map<String, URL> connect = new HashMap<String, URL>(); connect.put("url", new File(pathToShapefile).toURI().toURL()); DataStore dataStore = DataStoreFinder.getDataStore(connect); String[] typeNames = dataStore.getTypeNames(); for (int i = 0; i < typeNames.length; ++i) { String typeName = typeNames[i]; triplesMaps.put(typeName, ""); triplesMaps.put(typeName, triplesMaps.get(typeName) + printTriplesMap(typeName)); triplesMaps.put(typeName, triplesMaps.get(typeName) + printLogicalSource(typeName)); triplesMaps.put(typeName, triplesMaps.get(typeName) + printSubjectMap(baseURI, typeName)); FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName); FeatureType ft = featureSource.getSchema(); String typeNameGeo = typeNames[i] + "_Geometry"; for (PropertyDescriptor property : ft.getDescriptors()) { String identifier = property.getName().getLocalPart(); if (identifier.equals("the_geom")) { continue; } String datatype = TranslateDataTypeToXSD((property.getType().getBinding().getName())); Query q = new Query(); triplesMaps.put(typeName, triplesMaps.get(typeName) + printPredicateObjectMap(identifier, identifier, datatype, typeName)); } // triplesMaps.put(typeName, // triplesMaps.get(typeName) + printPredicateObjectMap(true, // "hasGeometry", // baseURI + (baseURI.endsWith("/") ? "" : "/") + typeNameGeo + // "/{GeoTriplesID}", null, // typeName, true)); triplesMaps .put(typeName, triplesMaps.get(typeName) + printPredicateObjectMap(true, "hasGeometry", baseURI + (baseURI.endsWith("/") ? "" : "/") + typeName + "/Geometry/{GeoTriplesID}", null, null, "ogc", null, typeName, true, false)); triplesMaps.put(typeNameGeo, ""); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printTriplesMap(typeNameGeo)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printLogicalSource(typeName)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printSubjectMap(baseURI, typeName, null, true)); triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printGEOPredicateObjectMaps()); } printmapping(); printontology(); }
Example #30
Source File: EnvironmentVariablePanelTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
@Override public Map<UserLayer, FeatureSource<SimpleFeatureType, SimpleFeature>> getUserLayerFeatureSource() { return null; }