0

I tried exporting data selecting it from postgres with spatial query. The argument does work within osGeo4W Shell but I'm trying to use it from my C# console app. Everything seems too work until I add the spatial part. I have no idea what could be the issue here, but I'm still a beginner. Can someone take a look and help me figure out what went wrong here?

// assemble input
string output = "C:\\Users\\martijn\\Documents\\output.gpkg";
string connectionPostgis = " PG:\"dbname = db_naam host = localhost user = postgres password = password port = 5432 \" ";
string sqlRequest = "-sql \"SELECT naam, geom,ST_Distance(ST_GeographyFromText(\'POINT(4.9235515 52.3770089)\'),geom) FROM public.table \"";
string argument ="ogr2ogr -f \"GPKG\" " + output + connectionPostgis + sqlRequest;
            
// process
Process process = new Process();
process.StartInfo.FileName = "C:\\OSGeo4W64\\OSGeo4W.bat";
process.StartInfo.Arguments = argument;

process.Start();
3
  • 1
    did you try printing sqlRequest and argument to console? to check if the escaping is correct
    – prusswan
    Mar 19, 2021 at 18:48
  • and after printing the command, try to run it in the database directly, so you can see the error message
    – JGH
    Mar 19, 2021 at 20:18
  • fist I tried the sqlRequest in pgAdmin 4v4 next in the command line. they seems to work without issue or error. (the comma was not the problem...)
    – Martijn
    Mar 22, 2021 at 7:06

1 Answer 1

0

The point is invalid. Remove the coma between the longitude and the latitude

ST_GeographyFromText(\'POINT(4.9235515 52.3770089)\')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.