Welcome to the BEAM Forum!

We encourage you to sign in our forum and participate in the BEAM community. The forum is maintained by the BEAM project team who will most likely answer your questions within 24 hours (except during common holidays) - if not done by other community members. Collaborate, share your knowledge and learn from other users!

If you don't find what you are looking for, please also consider the following external forums:

Combination View Flat View Tree View
Threads [ Previous | Next ]
Write out a shape file
Write out a shape file
1/17/16 5:11 AM
Long time since I asked a question. Given latitude and longitude in a netcdf file can I write out a shape file that I want using BEAM ?
Flag Flag
RE: Write out a shape file
1/18/16 11:33 AM as a reply to Ashwin D.
Not sure if I understand you correct. You want a shapefile which represents the shape of the NetCDF file?
Flag Flag
RE: Write out a shape file
1/19/16 2:12 AM as a reply to Marco Peters.
Yes. The netCDF file gives the latitude and longitude of a particular domain.

Can I generate a shape file out of that ?
Flag Flag
RE: Write out a shape file
1/19/16 9:53 AM as a reply to Ashwin D.
There is no existing method in BEAM.

But you can use the followingmethod .
 1    private static void writeProductBoundaryAsShapeFile(Product product, File outputShapeFile) throws IOException {
 2        final Geometry productBoundary = FeatureUtils.createGeoBoundaryPolygon(product);
 3        final SimpleFeatureType featureType = PlainFeatureFactory.createPlainFeatureType(PlainFeatureFactory.DEFAULT_TYPE_NAME, Polygon.class,
 4                                                                                         DefaultGeographicCRS.WGS84);
 5        final SimpleFeature productShape = PlainFeatureFactory.createPlainFeature(featureType, "ID#1", productBoundary, null);
 6        ShapefileDataStoreFactory factory = new ShapefileDataStoreFactory();
 7        Map map = Collections.singletonMap("url", outputShapeFile.toURI().toURL());
 8        ShapefileDataStore dataStore = (ShapefileDataStore) factory.createNewDataStore(map);
 9        dataStore.createSchema(featureType);
11        FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriterAppend(featureType.getTypeName(), Transaction.AUTO_COMMIT);
12        try {
13            SimpleFeature newFeature = writer.next();
14            newFeature.setAttributes(productShape.getAttributes());
15            writer.write();
16        } finally {
17            writer.close();
18        }
19    }

It is written straight forward and does not care for error handling and edge cases. I leave this up to you ;)
Flag Flag
RE: Write out a shape file
1/19/16 10:18 AM as a reply to Marco Peters.
Marco - great. I saw this functionality in Python as well in GeoTools. But the issue with GeoTools is that you have to worry about what packages to add to your build.

I will be sure to test this and enhance this but why don't you add it to the next release of BEAM ? :emoticon
Flag Flag
RE: Write out a shape file
1/19/16 10:34 AM as a reply to Ashwin D.
There will be no next release of BEAM. We further work on SNAP. Maybe I add it to SNAP if I find a cosy place for it.
Flag Flag
RE: Write out a shape file
1/19/16 12:14 PM as a reply to Marco Peters.
Very good Marco. Personally I liked the name BEAM more than SNAP. Obviously if you are a trekkie(BEAM me up Scotty!) you will understand why. But I guess I can SNAP out of it too.

Now I saw this thread here - KML Beam and I had been planning to write my KML writer and reader wrappers in Java using GeoTools but maybe you can save me the burden.

I have data from weather models such as wind vectors, rainfall numbers, radar data and I want to project this on Google Earth. This is usually in NetCDF. Can BEAM/SNAP help me ?
Flag Flag
RE: Write out a shape file
1/19/16 2:19 PM as a reply to Ashwin D.
Honestly I like BEAM more, too. It took some time and a lot of discussion to find the new name. Meanwhile I'm used to it and like it too.

For exporting to Kmz there is the class org.esa.beam.util.kmz.KmzExporter.
For example usage please have a look org.esa.beam.pixex.PixExOp,
org.esa.beam.timeseries.export.kmz.ExportTimeBasedKmz and also at the tests in the package org.esa.beam.util.kmz

Flag Flag