Hello,

I'm developing a GeoTiff export for a meteorological data viewer, using GeoTools (2.6.1).
The start point is an image containing the map. A lot of projections are possible (these are own projection implementations, no GeoTools projections) but I start with the stereographic projection.

I create the WKT, the model tie point and pixel scale which are passed to a GeoTiffIIOMetadataEncoder.
The tiff tags are then extracted from the GeoTiffIIOMetadataEncoder and passed to JAI which is used to write the GeoTiff.
Is there a way to create the GeoTiff from the image and GeoTiffIIOMetadataEncoder using only GeoTools?

My problem is that my projections work on a sphere instead of an ellipsoid.
I tried to adapt the SPHEROID inside the WKT but I can't get it running.


This is my code:


         StereographicProjection sp = (StereographicProjection)projection; //my own projection
         float[] pixelScaleLonLat = new float[] {(float)sp.getProjectionPointX(), (float)sp.getProjectionPointY()};
         float scale = (float)sp.getScale();

         String wkt = "PROJCS[\"Popular Visualisation CRS / Stereographic Projection\"," +
                  "GEOGCS[\"Popular Visualisation CRS\"," +
                     "DATUM[\"Popular Visualisation Datum\"," +
                        "SPHEROID[\"Sphere\",6378137,0]]," +
                     "PRIMEM[\"Greenwich\",0]," +
                     "UNIT[\"degree\",0.0174532925199433]]," +
                   "PROJECTION[\"CT_ObliqueStereographic\", AUTHORITY[\"EPSG\",\"9809\"]], " +
                   "PARAMETER[\"central_meridian\", "   + sp.getProjectionPointX() + "], " +
                   "PARAMETER[\"latitude_of_origin\", " + sp.getProjectionPointY() + "], " +
                   "PARAMETER[\"scale_factor\", "       + scale + "], " +
                   "PARAMETER[\"false_easting\",0]," +
                   "PARAMETER[\"false_northing\",0]," +
                   "PARAMETER[\"semi_major\",6378137], " +
                   "PARAMETER[\"semi_minor\",6378137], " +
                   "UNIT[\"m\", 1.0," +
                      "AUTHORITY[\"EPSG\",\"9001\"]]]";

         float[] tiePoint         = getModelTiePointInMeters4Stereographic(geoContext, pixelScaleLonLat, 1);
         float[] imageTiePoint    = getModelTiePointInPixels4Stereographic(geoContext, pixelScaleLonLat, 1);
         imageTiePoint[1] = img.getHeight() - imageTiePoint[1];
         if(scene.getClipScene())
            tiePoint[0] = tiePoint[1];
         double[] modelPixelScale = getPixelScale4Stereographic(geoContext, pixelScaleLonLat, scale);
         try {
            GeoTiffIIOMetadataEncoder encoder = new CRS2GeoTiffMetadataAdapter(CRS.parseWKT(wkt)).parseCoordinateReferenceSystem();
            encoder.setModelTiePoint(imageTiePoint[0], imageTiePoint[1], tiePoint[0], tiePoint[1]);
            encoder.setModelPixelScale(modelPixelScale[0], modelPixelScale[1], modelPixelScale[2]);
            encoder.addGeoShortParam(GeoTiffConstants.GTRasterTypeGeoKey, GeoTiffConstants.RasterPixelIsArea)

            //my own GeoTiff params
            GeoCodedRasterImageTags tags = new GeoCodedRasterImageTags()
            tags.setModelTiepoint(  encoder.getModelTiePoint().getData())
            tags.setModelPixelScale(modelPixelScale);

            for(int i=0 ; i < encoder.getNumGeoKeyEntries() ; i++) 
               GeoKeyEntry entry = encoder.getGeoKeyEntryAt(i);
               int id = entry.getKeyID();
               System.out.printf("ID: %s, Location: %s, Count: %s, ValueOffset: %s%n", id, entry.getTiffTagLocation(), entry.getCount(), entry.getValueOffset());
               if(     entry.getTiffTagLocation() == 0)     //offset == value
                  tags.setGeoKeyDirectoryEntry(id, entry.getValueOffset());
               else if(entry.getTiffTagLocation() == 34737) //GeoAsciiParamsTag      = 34737
                  tags.setGeoKeyDirectoryEntry(id, encoder.getGeoAsciiParam(id));
               else if(entry.getTiffTagLocation() == 34736) //GeoDoubleParamsTag     = 34736
                  tags.setGeoKeyDirectoryEntry(id, encoder.getGeoDoubleParam(id));
            }
            TIFFEncodeParam parameter    = new TIFFEncodeParam();
            parameter.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
            parameter.setExtraFields(tags.getTIFFFields());

            TIFFImageEncoder enc = new TIFFImageEncoder(new FileOutputStream(new File("/home/wab/test.stereographic.tiff")), parameter);
            enc.encode(img);
         }
         catch(Exception e) {
         }


The produced GeoTiff isn't recognized by gdalinfo from FWTools and cannot be opened by GIS software (ArcGisExplorer).

~>gdalinfo test.stereographic.tiff | grep Warning
Warning 1: TIFFFetchNormalTag:ASCII value for tag "GeoASCIIParams" contains null byte in value; value incorrectly truncated during reading due to implementation limitations
Warning 1: GeoTIFF tags apparently corrupt, they are being ignored.

However if I use WGS 84 the GeoTiff is ok (but it is inacurate because of differences in the used and specified ellipsoids):

         String wkt = "PROJCS[\"Popular Visualisation CRS / Stereographic Projection\"," +
                  "GEOGCS[\"WGS 84\"," +
                     "DATUM[\"WGS_1984\"," +
                        "SPHEROID[\"WGS 84\",6378137,298.2572235629972," +
                           "AUTHORITY[\"EPSG\",\"7030\"]]," +
                        "AUTHORITY[\"EPSG\",\"6326\"]]," +
                        "PRIMEM[\"Greenwich\",0]," +
                        "UNIT[\"degree\",0.0174532925199433]," +
                        "AUTHORITY[\"EPSG\",\"4326\"]]," +
                   "PROJECTION[\"CT_ObliqueStereographic\", AUTHORITY[\"EPSG\",\"9809\"]], " +
                   "PARAMETER[\"central_meridian\", "   + sp.getProjectionPointX() + "], " +
                   "PARAMETER[\"latitude_of_origin\", " + sp.getProjectionPointY() + "], " +
                   "PARAMETER[\"scale_factor\", "       + scale + "], " +
                   "PARAMETER[\"false_easting\",0]," +
                   "PARAMETER[\"false_northing\",0]," +
                   "UNIT[\"m\", 1.0," +
                      "AUTHORITY[\"EPSG\",\"9001\"]]]";

Please help me. How should I rearrange the WKT to specify a sphere?
Is there a better way instead of working with the WKT?

Thanks and best regards
Waldemar

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to