]> granicus.if.org Git - postgis/commitdiff
Keep UTM zone numbers in range, regress-test _ST_BestSRID (#1234)
authorSandro Santilli <strk@keybit.net>
Mon, 16 Jan 2012 17:00:50 +0000 (17:00 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 16 Jan 2012 17:00:50 +0000 (17:00 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8846 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/geography_measurement.c
regress/Makefile.in
regress/bestsrid.sql [new file with mode: 0644]
regress/bestsrid_expected [new file with mode: 0644]
regress/tickets.sql
regress/tickets_expected

index 9a6383b1488a80fe16fa7906bbbdc01e8397c8ba..22216132f1f51e585651030a477e74d6d9802cf6 100644 (file)
@@ -576,7 +576,8 @@ Datum geography_bestsrid(PG_FUNCTION_ARGS)
        {
                /* Cheap hack to pick a zone. Average of the box center points. */
                double dzone = (gbox1.xmin + gbox1.xmax + gbox2.xmin + gbox2.xmax) / 4.0;
-               int zone = floor(1.0 + ((dzone + 180.0) / 6.0));
+               int zone = floor((dzone + 180.0) / 6.0);
+               if ( zone > 59 ) zone = 59;
 
                /* Are these data below the equator? UTM South. */
                if ( gbox1.ymax < 0.0 && gbox2.ymax < 0.0 )
index a3fcae95e3cafd20b0dc26efd959867d97b8a3a9..5bf372e3e780e9aabeb69e11a678fb9eb19f5ca4 100644 (file)
@@ -91,6 +91,7 @@ TESTS = \
        remove_repeated_points \
        split \
        relate \
+       bestsrid \
        concave_hull
 
 # TESTS += wmsservers_old
diff --git a/regress/bestsrid.sql b/regress/bestsrid.sql
new file mode 100644 (file)
index 0000000..832122c
--- /dev/null
@@ -0,0 +1,25 @@
+-- South lambert
+select x, y, _ST_BestSRID(ST_Point(x, y))
+from ( select 0 as x, -70 as y ) as foo ;
+
+-- North lambert
+select x, y, _ST_BestSRID(ST_Point(x, y))
+from ( select 0 as x, 70 as y ) as foo ;
+
+-- UTM north
+select x, 60, _ST_BestSRID(ST_Point(x, 60))
+from generate_series(-177, 177, 6) as x ;
+-- Corner cases
+select -180, 60, _ST_BestSRID(ST_Point(-180, 60));
+select 180, 60, _ST_BestSRID(ST_Point(180, 60));
+
+-- UTM south
+select x, -60, _ST_BestSRID(ST_Point(x, -60))
+from generate_series(-177, 177, 6) as x;
+-- Corner cases
+select -180, -60, _ST_BestSRID(ST_Point(-180, -60));
+select 180, -60, _ST_BestSRID(ST_Point(180, -60));
+
+-- World mercator
+select 'world', _ST_BestSRID(ST_Point(-160, -40), ST_Point(160, 40));
+
diff --git a/regress/bestsrid_expected b/regress/bestsrid_expected
new file mode 100644 (file)
index 0000000..256038f
--- /dev/null
@@ -0,0 +1,127 @@
+0|-70|999161
+0|70|999061
+-177|60|999001
+-171|60|999002
+-165|60|999003
+-159|60|999004
+-153|60|999005
+-147|60|999006
+-141|60|999007
+-135|60|999008
+-129|60|999009
+-123|60|999010
+-117|60|999011
+-111|60|999012
+-105|60|999013
+-99|60|999014
+-93|60|999015
+-87|60|999016
+-81|60|999017
+-75|60|999018
+-69|60|999019
+-63|60|999020
+-57|60|999021
+-51|60|999022
+-45|60|999023
+-39|60|999024
+-33|60|999025
+-27|60|999026
+-21|60|999027
+-15|60|999028
+-9|60|999029
+-3|60|999030
+3|60|999031
+9|60|999032
+15|60|999033
+21|60|999034
+27|60|999035
+33|60|999036
+39|60|999037
+45|60|999038
+51|60|999039
+57|60|999040
+63|60|999041
+69|60|999042
+75|60|999043
+81|60|999044
+87|60|999045
+93|60|999046
+99|60|999047
+105|60|999048
+111|60|999049
+117|60|999050
+123|60|999051
+129|60|999052
+135|60|999053
+141|60|999054
+147|60|999055
+153|60|999056
+159|60|999057
+165|60|999058
+171|60|999059
+177|60|999060
+-180|60|999001
+180|60|999060
+-177|-60|999101
+-171|-60|999102
+-165|-60|999103
+-159|-60|999104
+-153|-60|999105
+-147|-60|999106
+-141|-60|999107
+-135|-60|999108
+-129|-60|999109
+-123|-60|999110
+-117|-60|999111
+-111|-60|999112
+-105|-60|999113
+-99|-60|999114
+-93|-60|999115
+-87|-60|999116
+-81|-60|999117
+-75|-60|999118
+-69|-60|999119
+-63|-60|999120
+-57|-60|999121
+-51|-60|999122
+-45|-60|999123
+-39|-60|999124
+-33|-60|999125
+-27|-60|999126
+-21|-60|999127
+-15|-60|999128
+-9|-60|999129
+-3|-60|999130
+3|-60|999131
+9|-60|999132
+15|-60|999133
+21|-60|999134
+27|-60|999135
+33|-60|999136
+39|-60|999137
+45|-60|999138
+51|-60|999139
+57|-60|999140
+63|-60|999141
+69|-60|999142
+75|-60|999143
+81|-60|999144
+87|-60|999145
+93|-60|999146
+99|-60|999147
+105|-60|999148
+111|-60|999149
+117|-60|999150
+123|-60|999151
+129|-60|999152
+135|-60|999153
+141|-60|999154
+147|-60|999155
+153|-60|999156
+159|-60|999157
+165|-60|999158
+171|-60|999159
+177|-60|999160
+-180|-60|999101
+180|-60|999160
+world|999000
index 16173bea583cf1bd5e7a2e8b7f810e5264c7f80d..20e6f0da1ac68ce9b4dbb46bf7bd58c8cbe04f54 100644 (file)
@@ -13,6 +13,8 @@ INSERT INTO spatial_ref_sys ( srid, proj4text ) VALUES ( 32602, '+proj=utm +zone
 INSERT INTO spatial_ref_sys ( srid, proj4text ) VALUES ( 32702, '+proj=utm +zone=2 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs ' );
 INSERT INTO spatial_ref_sys ( srid, proj4text ) VALUES ( 3395, '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ' );
 
+INSERT INTO spatial_ref_sys (srid,proj4text) VALUES (32707,'+proj=utm +zone=7 +south +ellps=WGS84 +datum=WGS84 +units=m +no_defs ');
+
 
 -- #2 --
 SELECT '#2', ST_AsText(ST_Union(g)) FROM
@@ -255,6 +257,7 @@ BEGIN
     END IF;
 
     zone:=floor((ST_X(geomgeog)+180)/6)+1;
+    IF ( zone > 60 ) THEN zone := 60; END IF;
 
     RETURN zone+pref;
 END;
@@ -265,10 +268,11 @@ CREATE TABLE utm_dots ( the_geog geography, utm_srid integer);
 INSERT INTO utm_dots SELECT geography(ST_SetSRID(ST_Point(i*10,j*10),4326)) As the_geog, utmzone(ST_SetSRID(ST_Point(i*10,j*10),4326)) As utm_srid FROM generate_series(-17,17) As i CROSS JOIN generate_series(-8,8) As j;
 
 SELECT ST_AsText(the_geog) as the_pt, 
+       utm_srid,
        ST_Area(ST_Buffer(the_geog,10)) As the_area, 
        ST_Area(geography(ST_Transform(ST_Buffer(ST_Transform(geometry(the_geog),utm_srid),10),4326))) As geog_utm_area
 FROM utm_dots 
-WHERE ST_Area(ST_Buffer(the_geog,10)) NOT between 310 and 314
+WHERE ST_Area(ST_Buffer(the_geog,10)) NOT between 307 and 314
 LIMIT 10;
 
 SELECT '#304.a', Count(*) FROM utm_dots WHERE ST_DWithin(the_geog, 'POINT(0 0)'::geography, 3000000);
@@ -370,7 +374,7 @@ SELECT '#696',ST_Segmentize(ST_GeomFromEWKT('PolyhedralSurface( ((0 0 0, 0 0 1,
 SELECT '#720', ST_AsText(ST_SnapTogrid(ST_Transform(ST_GeomFromText('MULTIPOINT(-10 40,-10 55,-10 70,5 40,5 55,5 70,20 40,20 55,20 70,35 40,35 55,35 70,50 40,50 55,50 70)',4326), 3395), 0.01));
 
 -- #723 --
-SELECT '#723',ST_Intersection(a.geog, b.geog) As result FROM (VALUES (ST_GeogFromText('SRID=4326;POINT(-11.1111111 40)') ), (ST_GeogFromText('SRID=4326;POINT(-11.1111111 55)') ) ) As  a(geog) CROSS JOIN ( VALUES (ST_GeogFromText('SRID=4326;POINT(-11.1111111 40)') ), (ST_GeogFromText('SRID=4326;POINT(-11.1111111 55)') )) As b(geog);  
+SELECT '#723',ST_Intersection(a.geog, b.geog) As result FROM (VALUES (ST_GeogFromText('SRID=4326;POINT(-11.1111111 40)') ), (ST_GeogFromText('SRID=4326;POINT(-11.1111111 55)') ) ) As  a(geog) CROSS JOIN ( VALUES (ST_GeogFromText('SRID=4326;POINT(-11.1111111 40)') ), (ST_GeogFromText('SRID=4326;POINT(-11.1111111 55)') )) As b(geog);
 
 -- #729 --
 --SELECT '#729',ST_MakeLine(foo1.the_geom) As result FROM ((SELECT ST_GeomFromText('POINT EMPTY',4326) As the_geom UNION ALL SELECT ST_GeomFromText('MULTIPOINT EMPTY',4326) As the_geom UNION ALL SELECT ST_GeomFromText('MULTIPOLYGON EMPTY',4326) As the_geom UNION ALL SELECT ST_GeomFromText('LINESTRING EMPTY',4326) As the_geom UNION ALL SELECT ST_GeomFromText('MULTILINESTRING EMPTY',4326) As the_geom ) ) As foo1;
index 83cbfacd5e32d8bb911f061c302dd4c88d819a33..04264619866853068816fcdb767120e493b59ecf 100644 (file)
@@ -116,10 +116,10 @@ ERROR:  Shell is not a line
 ERROR:  First argument must be a LINESTRING
 #696|010F000080060000000103000080010000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000010300008001000000050000000000000000000000000000000000000000000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F0000000000000000000000000000000000000000000000000000000000000000000000000000000001030000800100000005000000000000000000000000000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F0000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000000000000000000000000000000000001030000800100000005000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000010300008001000000050000000000000000000000000000000000F03F00000000000000000000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F00000000000000000103000080010000000500000000000000000000000000000000000000000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F000000000000F03F000000000000F03F0000000000000000000000000000F03F000000000000F03F00000000000000000000000000000000000000000000F03F
 #720|MULTIPOINT(-1113194.91 4838471.4,-1113194.91 7326837.72,-1113194.91 11028513.63,556597.45 4838471.4,556597.45 7326837.72,556597.45 11028513.63,2226389.82 4838471.4,2226389.82 7326837.72,2226389.82 11028513.63,3896182.18 4838471.4,3896182.18 7326837.72,3896182.18 11028513.63,5565974.54 4838471.4,5565974.54 7326837.72,5565974.54 11028513.63)
-#723|0101000020E6100000F480D98DE33826C0ACFCFFFFFFFF4340
+#723|0101000020E6100000270BD88DE33826C0C77EFFFFFFFF4340
 #723|0107000020E610000000000000
 #723|0107000020E610000000000000
-#723|0101000020E61000007975D98DE33826C060FBFFFFFF7F4B40
+#723|0101000020E61000004FFDD98DE33826C0BE4CFFFFFF7F4B40
 #804|<gml:Point srsName="urn:ogc:def:crs:EPSG::4326"><gml:pos srsDimension="2">0 0</gml:pos></gml:Point>
 #845|t
 #834|GEOMETRYCOLLECTION(POINT(0 0 5),LINESTRING(10 10 5,10 0 5))