Opened 14 years ago

Closed 14 years ago

#292 closed enhancement (fixed)

WKTWriter 3d support

Reported by: elpaso Owned by: warmerdam
Priority: major Milestone: 3.3.0
Component: Core Version: 3.1.1
Severity: Unassigned Keywords: dimension wkt
Cc:

Description

I noticed in WKTWriter.cpp the WRITE_Z option and activated it in order to have 3d WKT output.

I also had to patch CoordinateSequence.h to add getZ:

   /**
    * Returns ordinate Z (1) of the specified coordinate.
    *
    * @param index
    * @return the value of the Z ordinate in the index'th coordinate
    */
   virtual double getZ(size_t index) const { return getOrdinate(index, Z); }

It seems to work.

Is there any possibility to see this integrated in the code?

Change History (6)

comment:1 by strk, 14 years ago

It isn't fair to output Z if not explicitly requested by user. Also, it'd be worth outputting a standard 2.5d WKT if at all, which means "POINT Z (1 2 3)" rather than "POINT (1 2 3)".

I suggest you take a look at JTS to see if anything changed there since last port.

comment:2 by strk, 14 years ago

Oh, I've looked myself. JTS does allow user to specify if he wants Z too, but the implementation doesn't output proper (standard) WKT in that case and can also output invalid EWKT (postgis-defined) whereas the input geometry contains NAN z values (JTS outputs just no value for Z rather than 0.0 as PostGIS does).

comment:3 by pramsey, 14 years ago

Milestone: 3.3.0

comment:4 by warmerdam, 14 years ago

Keywords: dimension wkt added
Owner: changed from strk to warmerdam

I'm interested in taking this ticket on.

I'll note that getZ() isn't strictly required since there is a more general getOrdinate() available that can return X, Y, Z and M. It might be *nice* to have getZ(), but I'll leave that to someone else for now.

For this ticket I will focus on producing valid WKT for 2D or 3D geometries controlled by an outputDimension setting similar to the WKBWriter. My intention is to have the *default* output dimension be 2D, but the application can also set to 3D or to "-1" indicating the output geometry dimension should be determined from the input geometry which as of 3.3 has a reasonable chance of preserving 2D vs. 3D'ness.

I'll also aim to produce the "new style" 3D WKT ie. POINT Z (1 2 3), possibly with an option to produce old style: POINT (1 2 3)

comment:5 by warmerdam, 14 years ago

Status: newassigned

I have implemented support for writing old and new style 3D WKT (new is the default) in the WKTWriter. The new setOutputDimension() method can be used to allow 3D output (set to 3) while the default is to reduce 3D geometry to 2D in WKT. Also the setOld3D() method can be used to force writing pre SF1.2 3D WKT (without the Z after the geometry type).

Some unit tests added.

All in trunk as part of a larger commit (r2995).

Still need to extend C API.

comment:6 by warmerdam, 14 years ago

Resolution: fixed
Status: assignedclosed

Added GEOSWKTWriter_setOld3D() and GEOSWKTWriter_setOutputDimension() to C API (r2997).

Note: See TracTickets for help on using tickets.