View Ticket
Not logged in
Ticket Hash: b1fcb045a7241950faacebe51969c1e051073d53
Title: ST_HexagonalGrid and ST_TriangularGrid do not function with negative numbers in the geometry
Status: Closed Type: Code_Defect
Severity: Important Priority: Medium
Subsystem: Resolution: Fixed
Last Modified: 2015-06-05 15:18:59
Version Found In: spatialite_gui 1.8.0
User Comments:
anonymous added on 2015-06-02 21:19:21:
These two functions will return null values if negative numbers are present in the geometry.  ST_SquareGrid does not exhibit this problem.  Here is an example of data that will return the null value.

SELECT 
	ST_HexagonalGrid(ST_GeomFromText('
		POLYGON((
		-95.594541 32.135399, 
		-94.985265 32.135399,
		-94.985265 32.687026, 
		-95.594541 32.687026,
		-95.594541 32.135399))
	'), .3) as geom

bradh added on 2015-06-03 02:30:05:
On testing, there is another bug in the libspatialite tests (trianggrid20.testcase)

spatialite> SELECT AsText(TriangularGrid(GeomFromText('POLYGON((0.2 0.2, 2.2 0.2, 2.2 1.2, 0.2 1.2, 0.2 0.2))', 4326), 1.0));
MULTIPOLYGON(((0 0.866025, 1 0.866025, 0.5 1.732051, 0 0.866025)), ((0.5 1.732051, 1 0.866025, 1.5 1.732051, 0.5 1.732051)), ((1 0.866025, 2 0.866025, 1.5 1.732051, 1 0.866025)), ((1.5 1.732051, 2 0.866025, 2.5 1.732051, 1.5 1.732051)), ((2 0.866025, 3 0.866025, 2.5 1.732051, 2 0.866025)))
spatialite> SELECT ST_MinY(TriangularGrid(GeomFromText('POLYGON((0.2 0.2, 2.2 0.2, 2.2 1.2, 0.2 1.2, 0.2 0.2))', 4326), 1.0));
0.866025403784439

That is, there should be coverage for the whole polygon, but we're missing all of the area in the range Y=[0.2, 0.866025403784439)

sandro added on 2015-06-05 15:18:29:
confirmed:
- there was a first bug affecting all negative coordinate values
- a second bug caused the test loop to incorrectly start from an offset position