public static boolean isComplexFeature(FeatureCollectionResponse results) { boolean hasComplex = false; for (int fcIndex = 0; fcIndex < results.getFeature().size(); fcIndex++) { if (!(results.getFeature().get(fcIndex).getSchema() instanceof SimpleFeatureTypeImpl)) { hasComplex = true; break; } } return hasComplex; }
private BigInteger countFeature(FeatureCollectionResponse fct) { BigInteger count = BigInteger.valueOf(0); for (int fcIndex = 0; fcIndex < fct.getFeature().size(); fcIndex++) { FeatureIterator i = null; try { for (i = (((FeatureCollection) fct.getFeature().get(fcIndex)).features()); i.hasNext(); i.next()) { count = count.add(BigInteger.ONE); } } finally { if (i != null) { i.close(); } } } return count; }
List resultsList = results.getFeature(); FeatureCollection[] featureResults = (FeatureCollection[])
/** * Builds, configures and returns {@link GeoJSONBuilder} * * @param featureCollection * @param outWriter * @return */ protected GeoJSONBuilder getGeoJSONBuilder( FeatureCollectionResponse featureCollection, Writer outWriter) { final GeoJSONBuilder jsonWriter = new GeoJSONBuilder(outWriter); int numDecimals = getNumDecimals(featureCollection.getFeature(), gs, gs.getCatalog()); jsonWriter.setNumberOfDecimals(numDecimals); jsonWriter.setEncodeMeasures( encodeMeasures(featureCollection.getFeature(), gs.getCatalog())); return jsonWriter; }
/** * Saves the feature source contents into a zipped shapefile, returns the output as a byte array */ byte[] writeOut(FeatureCollection fc) throws IOException { ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fc); zip.write(fct, bos, op); return bos.toByteArray(); }
public String getAttachmentFileName(Object value, Operation operation) { SimpleFeatureCollection fc = (SimpleFeatureCollection) ((FeatureCollectionResponse) value).getFeature().get(0); FeatureTypeInfo ftInfo = getFeatureTypeInfo(fc.getSchema());
@Test public void testMultipleSameNamespace() throws Exception { FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(getFeatureSource(MockData.SEVEN).getFeatures()); fcType.getFeature().add(getFeatureSource(MockData.FIFTEEN).getFeatures()); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN, MockData.FIFTEEN)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals( 7 + 15, document.getElementsByTagName("cdf:Seven").getLength() + document.getElementsByTagName("cdf:Fifteen").getLength()); }
@Test public void testSingle() throws Exception { FeatureSource<? extends FeatureType, ? extends Feature> source = getFeatureSource(MockData.SEVEN); FeatureCollection<? extends FeatureType, ? extends Feature> features = source.getFeatures(); FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(features); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals(7, document.getElementsByTagName("cdf:Seven").getLength()); }
result.setTimeStamp(Calendar.getInstance()); result.setLockId(lockId); result.getFeature().addAll(results); result.setGetFeatureById(getFeatureById);
@Test public void testMultipleDifferentNamespace() throws Exception { FeatureCollectionResponse fcType = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fcType.getFeature().add(getFeatureSource(MockData.SEVEN).getFeatures()); fcType.getFeature().add(getFeatureSource(MockData.POLYGONS).getFeatures()); int npolys = getFeatureSource(MockData.POLYGONS).getFeatures().size(); ByteArrayOutputStream output = new ByteArrayOutputStream(); producer().write(fcType, output, request(MockData.SEVEN, MockData.POLYGONS)); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = docBuilder.parse(new ByteArrayInputStream(output.toByteArray())); assertEquals( 7 + npolys, document.getElementsByTagName("cdf:Seven").getLength() + document.getElementsByTagName("cgf:Polygons").getLength()); } }
@Test public void testCharset() throws Exception { FeatureSource<? extends FeatureType, ? extends Feature> fs; fs = getFeatureSource(SystemTestData.BASIC_POLYGONS); ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fs.getFeatures()); // add the charset Map options = new HashMap(); options.put("CHARSET", Charset.forName("ISO-8859-15")); gft.setFormatOptions(options); zip.write(fct, bos, op); checkShapefileIntegrity( new String[] {"BasicPolygons"}, new ByteArrayInputStream(bos.toByteArray())); assertEquals("ISO-8859-15", getCharset(new ByteArrayInputStream(bos.toByteArray()))); }
/** * Saves the feature source contents into a zipped shapefile, returns the output as a byte array */ byte[] writeOut(FeatureCollection fc, long maxShpSize, long maxDbfSize) throws IOException { ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); zip.setMaxDbfSize(maxDbfSize); zip.setMaxShpSize(maxShpSize); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fc); zip.write(fct, bos, op); return bos.toByteArray(); }
jsonWriter.key("features"); jsonWriter.array(); List<FeatureCollection> resultsList = featureCollection.getFeature(); FeaturesInfo featuresInfo = writeFeatures(resultsList, operation, isComplex, jsonWriter);
@Test public void testTemplateMultiType() throws Exception { // copy the new template to the data dir WorkspaceInfo ws = getCatalog().getWorkspaceByName(SystemTestData.BASIC_POLYGONS.getPrefix()); getDataDirectory() .copyToWorkspaceDir( ws, getClass().getResourceAsStream("shapeziptest.ftl"), "shapezip.ftl"); // setup the request params ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature() .add(getFeatureSource(SystemTestData.BASIC_POLYGONS).getFeatures(Filter.INCLUDE)); fct.getFeature().add(getFeatureSource(SystemTestData.BRIDGES).getFeatures(Filter.INCLUDE)); // get the file name assertEquals("shapezip_BasicPolygons.zip", zip.getAttachmentFileName(fct, op)); // check the contents zip.write(fct, bos, op); byte[] zipBytes = bos.toByteArray(); checkShapefileIntegrity( new String[] {"theshape_BasicPolygons", "theshape_Bridges"}, new ByteArrayInputStream(zipBytes)); }
@Test public void testESRIFormat() throws Exception { setupESRIPropertyFile(); FeatureSource<? extends FeatureType, ? extends Feature> fs; fs = getFeatureSource(SystemTestData.BASIC_POLYGONS); ShapeZipOutputFormat zip = new ShapeZipOutputFormat(getGeoServer(), getCatalog(), getResourceLoader()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fs.getFeatures()); // add the charset Map options = new HashMap(); options.put("PRJFILEFORMAT", "ESRI"); gft.setFormatOptions(options); zip.write(fct, bos, op); byte[] byteArrayZip = bos.toByteArray(); checkShapefileIntegrity( new String[] {"BasicPolygons"}, new ByteArrayInputStream(byteArrayZip)); checkFileContent( "BasicPolygons.prj", new ByteArrayInputStream(byteArrayZip), get4326_ESRI_WKTContent()); }
@Test public void testTemplateSingleType() throws Exception { // copy the new template to the data dir WorkspaceInfo ws = getCatalog().getWorkspaceByName(SystemTestData.BASIC_POLYGONS.getPrefix()); getDataDirectory() .copyToWorkspaceDir( ws, getClass().getResourceAsStream("shapeziptest.ftl"), "shapezip.ftl"); // setup the request params SimpleFeatureCollection fc = getFeatureSource(SystemTestData.BASIC_POLYGONS).getFeatures(Filter.INCLUDE); ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fc); // get the file name assertEquals("shapezip_BasicPolygons.zip", zip.getAttachmentFileName(fct, op)); // check the contents zip.write(fct, bos, op); byte[] zipBytes = bos.toByteArray(); checkShapefileIntegrity( new String[] {"theshape_BasicPolygons"}, new ByteArrayInputStream(zipBytes)); }
@Test public void testTemplateMultiGeomType() throws Exception { // copy the new template to the data dir WorkspaceInfo ws = getCatalog().getWorkspaceByName(ALL_DOTS.getPrefix()); getDataDirectory() .copyToWorkspaceDir( ws, getClass().getResourceAsStream("shapeziptest.ftl"), "shapezip.ftl"); // setup the request params ShapeZipOutputFormat zip = new ShapeZipOutputFormat(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(getFeatureSource(ALL_DOTS).getFeatures(Filter.INCLUDE)); // get the file name assertEquals("shapezip_All_Types_Dots.zip", zip.getAttachmentFileName(fct, op)); // check the contents zip.write(fct, bos, op); byte[] zipBytes = bos.toByteArray(); checkShapefileIntegrity( new String[] { "theshape_All_Types_DotsPoint", "theshape_All_Types_DotsMPoint", "theshape_All_Types_DotsPolygon", "theshape_All_Types_DotsLine" }, new ByteArrayInputStream(zipBytes)); }
@Test public void testESRIFormatMultiType() throws Exception { setupESRIPropertyFile(); ShapeZipOutputFormat zip = new ShapeZipOutputFormat(getGeoServer(), getCatalog(), getResourceLoader()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(getFeatureSource(ALL_TYPES).getFeatures()); Map options = new HashMap(); options.put("PRJFILEFORMAT", "ESRI"); gft.setFormatOptions(options); zip.write(fct, bos, op); byte[] byteArrayZip = bos.toByteArray(); final String[] expectedTypes = new String[] {"AllTypesPoint", "AllTypesMPoint", "AllTypesPolygon", "AllTypesLine"}; checkShapefileIntegrity(expectedTypes, new ByteArrayInputStream(byteArrayZip)); for (String fileName : expectedTypes) { checkFileContent( fileName + ".prj", new ByteArrayInputStream(byteArrayZip), get4326_ESRI_WKTContent()); } }
@Test public void testESRIFormatFromDefaultValue() throws Exception { setupESRIPropertyFile(); final GeoServer geoServer = getGeoServer(); setupESRIFormatByDefault(geoServer, true); final FeatureSource fs = getFeatureSource(SystemTestData.BASIC_POLYGONS); final Catalog catalog = getCatalog(); final GeoServerResourceLoader resourceLoader = getResourceLoader(); ShapeZipOutputFormat zip = new ShapeZipOutputFormat(geoServer, catalog, resourceLoader); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FeatureCollectionResponse fct = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); fct.getFeature().add(fs.getFeatures()); // add the charset Map options = new HashMap(); gft.setFormatOptions(options); zip.write(fct, bos, op); byte[] byteArrayZip = bos.toByteArray(); checkShapefileIntegrity( new String[] {"BasicPolygons"}, new ByteArrayInputStream(byteArrayZip)); checkFileContent( "BasicPolygons.prj", new ByteArrayInputStream(byteArrayZip), get4326_ESRI_WKTContent()); }
@Test public void testOutputZipFileNameSpecifiedInFormatOptions() throws Exception { ShapeZipOutputFormat zip = new ShapeZipOutputFormat(getGeoServer(), getCatalog(), getResourceLoader()); FeatureCollectionResponse mockResult = FeatureCollectionResponse.adapt(WfsFactory.eINSTANCE.createFeatureCollectionType()); mockResult.getFeature().add(getFeatureSource(ALL_DOTS).getFeatures(Filter.INCLUDE)); GetFeatureType mockRequest = WfsFactory.eINSTANCE.createGetFeatureType(); Operation mockOperation = new Operation( "GetFeature", getServiceDescriptor10(), null, new Object[] {mockRequest}); assertEquals("All_Types_Dots.zip", zip.getAttachmentFileName(mockResult, mockOperation)); mockRequest.getFormatOptions().put("FILENAME", "REQUEST_SUPPLIED_FILENAME.zip"); assertEquals( "REQUEST_SUPPLIED_FILENAME.zip", zip.getAttachmentFileName(mockResult, mockOperation)); }