Oleksandr and Jody,

I came across a the same issue attempting to generate a CRS representing a data 
set with longitudes ranging from 0-360 with some NetCDF files we are attempting 
to access.  I expanded on code presented earlier in this thread and appear to 
have a working, invertible solution.

There are some questions below the code...

====
            boolean longitude360 = projectionRect.getMaxX() > 180;  // 
NetCDF-Java call
            if (longitude360) {
                
                Map<String, Object> crsPoperties = new HashMap<String, 
Object>();
                
                crsPoperties.put(IdentifiedObject.NAME_KEY, "CRS LON [0,360]");

                ExtentImpl extent = new ExtentImpl();
                List<GeographicExtent> extentList = new 
ArrayList<GeographicExtent>();
                extentList.add(new GeographicBoundingBoxImpl(0, 360, -90, 90));
                extent.setGeographicElements(extentList);
                crsPoperties.put(ReferenceSystem.DOMAIN_OF_VALIDITY_KEY, 
extent);

                return new DefaultDerivedCRS(
                    "CF-Derived CRS LON [0,360]",
                    geographicCRS,  // this is generated in other code using 
NetCDF-CF attriburtes
                    LongitudeDegreesTransform,  // instance referenced below
                    DefaultEllipsoidalCS.GEODETIC_2D);
            } else {
                return geographicCRS;
            }

[snip...]

    private final static ParameterDescriptorGroup EMPTY_PARAMETER_DESCRIPTORS =
                                new DefaultParameterDescriptorGroup("", new 
GeneralParameterDescriptor[0] );

    // Transform longitude from [-180...180] to [0...360]
    private final static MathTransform LongitudeDegreesTransform = new 
AbstractMathTransform() {

        @Override public int getSourceDimensions() { return 2; }
        @Override public int getTargetDimensions() { return 2; }

        @Override
        public ParameterDescriptorGroup getParameterDescriptors() {
                        return EMPTY_PARAMETER_DESCRIPTORS;
                }

        @Override
        public MathTransform inverse() throws NoninvertibleTransformException {
            return LongitudeDegreesInverseTransform;
        }

        @Override
        public void transform(double[] srcPts, int srcOff, double[] dstPts, int 
dstOff, int numPts) throws TransformException {
            int count = numPts * 2;
            for (int index = 0; index < count; index += 2) {
                double lon = srcPts[srcOff + index];
                dstPts[dstOff + index] = 180.0 + Math.IEEEremainder(lon - 
180.0, 360.0);
                dstPts[dstOff + index + 1] = srcPts[srcOff + index + 1];
            }
        }
    };

    // Transform longitude from [0...360] to [-180...180]
    private final static MathTransform LongitudeDegreesInverseTransform = new 
AbstractMathTransform() {

        @Override public int getSourceDimensions() { return 2; }
        @Override public int getTargetDimensions() { return 2; }

        @Override
                public ParameterDescriptorGroup getParameterDescriptors() {
                        return EMPTY_PARAMETER_DESCRIPTORS;
                }

        @Override
        public MathTransform inverse() throws NoninvertibleTransformException {
            return LongitudeDegreesTransform;
        }

        @Override
        public void transform(double[] srcPts, int srcOff, double[] dstPts, int 
dstOff, int numPts) throws TransformException {
            int count = numPts * 2;
            for (int index = srcOff; index < count; index += 2) {
                double lon = srcPts[srcOff + index];
                dstPts[dstOff + index] = Math.IEEEremainder(lon + 180.0, 360.0) 
- 180.0;
                dstPts[dstOff + index + 1] = srcPts[srcOff + index + 1];
            }
        }
    };
====

Questions:

1) What do I need to place in the ParameterDescriptorGroup instance for each of 
the transforms?
2) How would I register this transform so that it is available by the 
appropriate factory and/or can be resolved by WKT?
3) Did I spend a few hours duplicating something that already exists in 
GeoTools?
4) Is this code potentially affected by the presence of the forceXY system 
property (forget the exact name but it's the flag to ignore the authority 
defined axis order)

Thanks much,

Tom

On Feb 20, 2011, at 5:50 PM, Oleksandr Huziy wrote:

> Hello,
> 
> I printed their wkts and they are the same.
> GEOGCS["WGS84(DD)", 
>   DATUM["WGS84", 
>     SPHEROID["WGS84", 6378137.0, 298.257223563]], 
>   PRIMEM["Greenwich", 0.0], 
>   UNIT["degree", 0.017453292519943295], 
>   AXIS["Geodetic longitude", EAST], 
>   AXIS["Geodetic latitude", NORTH]]
> 
> 
> 
> GEOGCS["WGS84(DD)(0..360,-90..90)", 
>   DATUM["WGS84", 
>     SPHEROID["WGS84", 6378137.0, 298.257223563]], 
>   PRIMEM["Greenwich", 0.0], 
>   UNIT["degree", 0.017453292519943295], 
>   AXIS["Geodetic longitude", EAST], 
>   AXIS["Geodetic latitude", NORTH]]
> 
> What is different is the domain of validity
> 
> Extent:
>   Geographic Elements:
>     West Bound Longitude: 0
>     East Bound Longitude: 360
>     South Bound Latitude: -90
>     North Bound Latitude: 90
>     Inclusion: true
> 
> Extent:
>   Geographic Elements:
>     West Bound Longitude: -180
>     East Bound Longitude: 180
>     South Bound Latitude: -90
>     North Bound Latitude: 90
>     Inclusion: true
> 
> 
> I tried to convert the point (270, 0) from the defined CRS to WGS84 using 
> MathTransform,
> but it did not change. I think I should define the transformation operation, 
> but don't know how.
> I want to be able to reproject to this crs from shapefile using Query, for 
> example.
> 
> 
> thank you.
> 
> --
> Oleksandr
> 
> 2011/2/20 Jody Garnett <[email protected]>
> Not sure I understand; take your defaultCRS constructed below and print it 
> out as WKT to see the WKT representation. At least that will show us how to 
> do it :-)
> 
> As for hooking it up; as long as you have made the CoordianteReferenceSystem 
> data structure it is hooked up; you should be able to transform to any other 
> CoordinateReferenceSystem that geotools supports.
> 
> Note that the EPSG codes and WGS84 are nothing magic; GeoTools supports the 
> data structure; and the EPSG codes are just an easy way to fill in the 
> correct data structure.
> 
> -- 
> Jody Garnett
> 
> On Monday, 21 February 2011 at 1:53 AM, Oleksandr Huziy wrote:
> 
>> Hello,
>> 
>> thanks for your reply.
>> 
>> I don't think that extent can be specified in wkt, at least I did not find a 
>> way to do it.
>> I managed to specify the extent like below:
>> 
>>     public static CoordinateReferenceSystem getDefaultCRS() throws 
>> FactoryException{
>> 
>>         if (defaultCRS != null){
>>             return defaultCRS;
>>         }
>> 
>>         Map<String,Object> properties = new HashMap<String,Object>(4);
>>         properties.put(NAME_KEY, "WGS84(DD)(0..360,-90..90)"); 
>>         
>> 
>>         ExtentImpl extent = new ExtentImpl();
>>         Collection<GeographicExtent> col = new ArrayList<GeographicExtent>();
>>         col.add(new GeographicBoundingBoxImpl(0,360, -90, 90));
>>         extent.setGeographicElements(col);
>>         properties.put(DOMAIN_OF_VALIDITY_KEY, extent);
>>         defaultCRS = new DefaultGeographicCRS(properties, 
>> DefaultGeodeticDatum.WGS84,
>>                                             
>> DefaultEllipsoidalCS.GEODETIC_2D);
>> 
>> 
>>         return defaultCRS;
>>     }
>> 
>> 
>>     public static void main(String[] args) throws IOException, 
>> FactoryException {
>>         System.out.println(DefaultGeographicCRS.WGS84.getDomainOfValidity());
>>         System.out.println(DefaultGeographicCRS.WGS84.toWKT());
>>         System.out.println(getDefaultCRS().getDomainOfValidity());
>>     }
>> 
>> 
>> But now how to connect this crs with WGS84 and other default coordinates, in 
>> order to seamlessly use JTS.transform() ?
>> 
>> thank you
>> --
>> Oleksandr
>> 
>> 
>> 2011/2/20 Jody Garnett <[email protected]>
>>> The easy way is to parse from well known text. 
>>> 
>>> See:
>>> - http://docs.codehaus.org/display/GEOTDOC/01+CRS+Helper+Class
>>> 
>>> -- 
>>> Jody Garnett
>>> 
>>> On Sunday, 20 February 2011 at 2:26 PM, Oleksandr Huziy wrote:
>>> 
>>>> Hello,
>>>> 
>>>> Is there an easy way to get from DefaultGeograficCRS.WGS84 an object with 
>>>> the same datum, but for which longitude changes from 0 to 360?
>>>> 
>>>> I want it because I have polygons intersecting 180 degrees. 
>>>> So the points on the different size of 180 meridian are connected using 
>>>> the longer arc  from for example -179 to 179 giving dlon=358 degrees, but 
>>>> I want dlon=2 degrees.
>>>> 
>>>> Or maybe it is possible to change the prime meridian?
>>>> I looked at the examples at codehaus, but they are not up-to-date, since 
>>>> the factories used there does not exist anymore.
>>>> 
>>>> thank you for any help.
>>>> 
>>>> --
>>>> Oleksandr Huziy
>>>> ------------------------------------------------------------------------------
>>>> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
>>>> Pinpoint memory and threading errors before they happen.
>>>> Find and fix more than 250 security defects in the development cycle.
>>>> Locate bottlenecks in serial and parallel code that limit performance.
>>>> http://p.sf.net/sfu/intel-dev2devfeb
>>>> _______________________________________________
>>>> Geotools-gt2-users mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>> 
>> 
> 
> 
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb_______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to