Opened 16 years ago

Closed 14 years ago

#2762 closed defect (fixed)

PHP MapScript shapeObj->toWkt() returns single point for multipoint geometry

Reported by: mgleahy Owned by: mapserverbugs
Priority: normal Milestone:
Component: MapScript-PHP Version: 5.2
Severity: normal Keywords:
Cc: aboudreault

Description

Change History (6)

comment:1 by aboudreault, 14 years ago

Is this ticket still valid?

comment:2 by aboudreault, 14 years ago

Cc: aboudreault added

comment:3 by mgleahy, 14 years ago

Yes, I just tested it with PHP mapscript 5.6.3 on Ubuntu 10.04, using the packages from the UbuntuGIS unstable repo, and it still happens.

I eventually created a php class works around this for me:

class My_ShapeObj
{

	/**
	 * Return the geometry in Well Known Text format - basically, this
	 *  is a proxy for the $oShape->toWkt() method, but corrects for
	 *  multi-point geometries which are not currently working (where
	 *  it instead returns WKT for just the first point found in the
	 *  geometry object).
	 *
	 * @param shapeObj $oShape
	 */
	public function toWkt($oShape)
	{
		if ($oShape->type!=MS_SHAPE_POINT || $oShape->numlines<=1)
		{
			return $oShape->toWkt();
		}
		
		// This appears to be a point shape with more than one lineObj.
		else
		{
			$aWkt = array();
			
			// Each line is simply a lineObj containing one pointObj:
			for ($i=0;$i<$oShape->numlines;$i++)
			{
				$oPoint = $oShape->line($i)->point(0);
				$aWkt[] = $oPoint->x." ".$oPoint->y;
			}
			
			// Fixed WKT:
			return "MULTIPOINT(".implode(",",$aWkt).")";
		}
	}
}

The above can be called to translate multipoints into appropriate WKT like so:

$sWkt = My_ShapeObj::toWkt($oShape);

comment:4 by aboudreault, 14 years ago

All right, I'll take care to check this.

comment:5 by aboudreault, 14 years ago

mgleahy, I guess you experienced this bug using a postgis layer? Am I right?

comment:6 by aboudreault, 14 years ago

Resolution: fixed
Status: newclosed

Note that with this fix, the change made in #2443 could be removed. (r7558)

Fixed and committed in r10205.

Note: See TracTickets for help on using tickets.