On 07/11/09 18:57, Paragon Corporation wrote:
> Maxime,
> 
> ST_AsText does not produce the fidelity of the geometry.  It truncates
> floating points and I think where they truncate between GEOS and PostGIS is
> different.   GEOS and PostGIS do not share the same WKT writers.
> 
> My question is -- have you tried validating the WKB in GEOS.  The WKB should
> maintain fidelity so you should get the same IsValid answer in both those
> cases. 

Hi,

Thanks for the answer.

I've indeed tested the validity of the geometry loaded from the WKB in
Geos and it says it isn't valid whereas ST_IsValid says it is valid.

I've attached the test program I use. geom_1 is the WKB and geom_2 is
the WKT given by AsText. For geos both are invalid whereas for PostGIS
they're both valid.

Here is my output (i've squeezed the WKT output) :

g1->isValid : 0
g2->isValid : 0
[...]
ST_IsValid(geom1) : t

g1 is the geos::geom::Geometry corresponding to geom1.

I use the pqxx the library to perform PostGIS operations.

-- 
yabo
#include <locale.h>
#include <iostream>
#include <vector>
#include <sstream>

#include <pqxx/pqxx>

#include <geos/geom/MultiPolygon.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/Point.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKTWriter.h>
#include <geos/io/WKBReader.h>
#include <geos/io/WKBWriter.h>
#include <geos/operation/valid/IsValidOp.h>

int main(int argc, char* argv[])
{
  geos::geom::PrecisionModel pm(100);
  geos::geom::GeometryFactory gf(&pm);
  geos::io::WKTReader wktr(&gf);
  geos::io::WKBReader wkbr(gf);
  geos::io::WKTWriter wktw;

  const char* geom1 = 
"010600000002000000010300000001000000190000008ABE1B63A5E631C1B805225A9ABE1E416DE8A04D320C32C1D7F8FC07F2E71D41C297F8957F8431C12E340092AF261B41EFBCBC1C6C8831C1DD527C189B1A1B414C65FCC9717631C18040D7D6ABD21A41A93F856DE35C31C1EE69F7DEF054194124AB3292787631C10FAFE62B3DD71741BFEE6F7B56BC31C1CA209613D6BF1641E1D4E7EBC41B32C194D7361C98591641FF3A066E3A5532C1BF792B10339716418FC6FAB02A5732C1BC575737877F1641CA331779EE8E33C10A88632908181841A7DA0C03BA3E38C1009795B9D8BA1341A7DA0C03BA3E38C1FF9695B9D8BA134100000000006A38C14703ED7D8D92134100000000006A38C1EFD17A9648B2194160257F612DCE33C128BF5725DFFC1D41EDF8625FC9D533C1854369717D6E1E41ECA26E7D36BC33C1C6DEF59033EC1F411BE5D33B5A7633C1245E06A4D081204166666666EC1633C133333325F4B420418CFB33BC76B732C13F59B498C7812041046F5E7996AB32C1B5EECA1A056A2041F02482C97FA932C10F364460FD6F20418ABE1B63A5E631C1B805225A9ABE1E410103000000010000002E000000A7DA0C03BA3E3841494AE55AFD891941BA74389B2D403841A1E5D8340C71194190104B9B2D40384155D7EC340C71194118422003BA3E3841B35BF75AFD89194100000000006A3841EFD17A9648B2194100000000006A38414703ED7D8D9213415925F3FC2B6636415B2658AF3DB211413702665CB8643641C68467652FCB114185917E7AE13A364194D7361C5C9E11410A30294074DB3541EB307C29AC0412410C9EF5E85AA43541432A585B19E11241CB8C57CCE0A03541B5192D91EBD61241F573183224C83441EF7DF55B7B77174182992369C81C34411FA20BBEA0AD1741C13AC6F5BAF13341EC2AC437F4B216410A4D95B9969234414252DD02405E1541DD0DD1AAC6913441C3BDE34E1C581541DA6A32AABB983441194C02CBA65015411A016A9C94DE34418040D7D62B391441BD26E1F822F83441EE69F7DE70BB124142BB33D48DDE34410FAFE62BBD3D1141A777F6EAAF983441CA2096135626104185917E7A4139344128AF6D3830800F4113B957C5C4E03341C2628372F71E1041F6B26A46F5DF3341BEAD22FDD7181041F6B26A46D3813241BEAD22FD6FFE124113B957C5A2823241C26283728F0413410A302940B27B3241EB307C29000C13416C013BA6D73532418638317F74231441796D0307471C32411FDD020B2DA115417AC3F7E8D935324160788F2AE31E1741DD5645F996403241A0B186E9D649174121D081E6D23D3241EA1670AA7051174121D081E694203341B7E33C77BD791C41DD5645F9582333416D7E53B623721C414B81922A785E3341B02273AE9D5E1D4100000000E6BD3341CDCCCCB0E4C41D41B5A572C0A9CC334174C7B73010B51D414DA4FFCBEDCC33410A5B8AB885C21D414DA4FFCB7B3D35413D8EBDEB104E1D41B5A572C0373D3541A7FAEA639B401D41DA6A32AAE98D3541194C02CB16EA1C41B839CD89FEC435413F442E07B10D1C413573A83379C835414BE6D26EE0171C41B62C697D718A36419C0843F2BEF31741A7DA0C03BA3E3841494AE55AFD891941";
  const char* geom2 = "MULTIPOLYGON(((-1173157.38714209 
503718.58802041,-1182770.30323651 489980.507800949,-1148031.58582448 
444843.892578903,-1149036.11225491 444070.773911757,-1144433.7890075 
439466.959805496,-1137891.42781446 415036.217740684,-1144440.57108564 
390607.292872176,-1162326.48217671 372725.519127381,-1186756.92150622 
366182.027552956,-1201466.42978257 370124.765790846,-1201962.69132653 
368609.804044124,-1281774.47301029 394754.040418745,-1588922.01191489 
323254.181234702,-1588922.01191489 323254.181234702,-1600000 
320675.372974445,-1600000 421010.146952896,-1297965.38084634 
491319.78646754,-1299913.37260395 498591.360753112,-1293366.48996943 
523020.89156292,-1275482.23370201 540904.320361082,-1251052.4 
547450.07265625,-1226614.73516819 540899.798250951,-1223574.47409719 
537858.552329502,-1223039.78714209 538622.68802041,-1173157.38714209 
503718.58802041)),((1588922.01191489 418431.338765298,1589293.6063302 
416835.051608646,1589293.60661415 416835.051684727,1588922.01221097 
418431.338834222,1600000 421010.146952896,1600000 
320675.372974445,1467947.98808511 289935.421234702,1467576.36093153 
291531.849027705,1456865.47849378 288663.027552956,1432436.25062847 
295211.040512814,1418330.90999782 309318.339203511,1417440.79821091 
308666.891773607,1361956.19568562 384478.839803665,1318088.41069946 
387944.185591252,1307066.96005599 371901.054459258,1348246.7249344 
350096.002797399,1348038.66725241 349703.077040639,1349819.66483181 
349225.698250951,1367700.6109925 331338.959805496,1374242.97218554 
306908.217740684,1367693.82891436 282479.292872176,1349807.91782329 
264597.519127381,1325377.47849378 258054.027552956,1302724.7708698 
264125.861829322,1302517.2750656 263733.997202601,1212883.2750656 
311195.997202601,1213090.7708698 311587.861829322,1211314.25062847 
312064.040512814,1193431.64933785 329949.1242112,1186887.02739605 
354379.260753112,1193433.91003057 378808.79156292,1196182.97371428 
381557.728052879,1195474.90041829 382044.166443213,1253524.90041829 
466543.366443213,1254232.97371428 466056.928052879,1269368.16629799 
481191.420361082,1293798 487737.17265625,1297577.75174938 
486724.047576062,1297645.79686953 487585.430215285,1391995.79686953 
480132.230215285,1391927.75174938 479270.847576062,1412585.66483181 
473733.698250951,1426686.53828774 459628.257012431,1427577.20178909 
460280.108226393,1477233.48988609 392431.736583838,1588922.01191489 
418431.338765298)))";

  std::istringstream istr(geom1);
  geos::geom::Geometry* g1 = wkbr.readHEX(istr);

  std::string w1 = wktw.write(g1);

  geos::geom::Geometry* g2 = wktr.read(w1);

  std::string w2 = wktw.write(g2);

  std::cout << "g1->isValid : " << g1->isValid() << std::endl;
  std::cout << "g2->isValid : " << g2->isValid() << std::endl;

  if (w1 != w2)
  {
    std::cout << "w1 : " << w1 << std::endl
              << "w2 : " << w2 << std::endl;
  }

  if (w1 != geom2)
  {
    std::cout << "w1 : " << w1 << std::endl
              << "g2 : " << geom2 << std::endl;
  }

  // Checking validity in PostGIS via pqxx

  pqxx::connection db("host=localhost dbname=fag-test_tmp user=postgres");
  pqxx::work xaction(db, "gis");

  std::string query = std::string("SELECT ST_IsValid('") + geom1 + "');";
  const pqxx::result r = xaction.exec(query);
  xaction.commit();

  //assert(r.size() == 1)
  std::cout << "ST_IsValid(geom1) : " << r[0][0].c_str() << std::endl;
}
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to