Import raster by raster2pgsql, but get a sql syntax error - sql

I try to import a raster file into my postgres database following this tutorial [http://www.postgis.org/documentation/manual-svn/using_raster.xml.html][1]
Environment: windows7, Postgres 8.4, postgis 2.0.
My command line are:
cd C:\Program Files (x86)\PostgreSQL\8.4\bin
raster2pgsql -s 4236 -I -G -M kiwi.jpg -F -t 100x100 public.gis > out.sql
psql -U postgres -d mydb2 -f out.sql
The picture named "kiwi" was in the "C:\Program Files (x86)\PostgreSQL\8.4\bin" folder.
The out.sql can be generated successfully. But after input "psql -U postgres -d mydb2 -f out.sql" , there is an error.
psql:out.sql:98: ERROR: syntax error at or near"Available"
LINE 1: Available GDAL raster formats:
Thank you!
This is the contents of the query:(I'm very new about postgis, so I can't figure out what's wrong here. Because I just follow the tutorial, it should work )
Available GDAL raster formats:
Virtual Raster
GeoTIFF
National Imagery Transmission Format
Raster Product Format TOC format
ECRG TOC format
Erdas Imagine Images (.img)
CEOS SAR Image
CEOS Image
JAXA PALSAR Product Reader (Level 1.1/1.5)
Ground-based SAR Applications Testbed File Format (.gff)
ELAS
Arc/Info Binary Grid
Arc/Info ASCII Grid
GRASS ASCII Grid
SDTS Raster
DTED Elevation Raster
Portable Network Graphics
JPEG JFIF
In Memory Raster
Japanese DEM (.mem)
Graphics Interchange Format (.gif)
Graphics Interchange Format (.gif)
Envisat Image Format
Maptech BSB Nautical Charts
X11 PixMap Format
MS Windows Device Independent Bitmap
SPOT DIMAP
AirSAR Polarimetric Image
RadarSat 2 XML Product
PCIDSK Database File
PCRaster Raster File
ILWIS Raster Map
SGI Image File Format 1.0
SRTMHGT File Format
Leveller heightfield
Terragen heightfield
USGS Astrogeology ISIS cube (Version 3)
USGS Astrogeology ISIS cube (Version 2)
NASA Planetary Data System
EarthWatch .TIL
ERMapper .ers Labelled
NOAA Polar Orbiter Level 1b Data Set
FIT Image
GRIdded Binary (.grb)
Raster Matrix Format
EUMETSAT Archive native (.nat)
Idrisi Raster A.1
Intergraph Raster
Golden Software ASCII Grid (.grd)
Golden Software Binary Grid (.grd)
Golden Software 7 Binary Grid (.grd)
COSAR Annotated Binary Matrix (TerraSAR-X)
TerraSAR-X Product
DRDC COASP SAR Processor Raster
R Object Data Store
Portable Pixmap Format (netpbm)
USGS DOQ (Old Style)
USGS DOQ (New Style)
ENVI .hdr Labelled
ESRI .hdr Labelled
Generic Binary (.hdr Labelled)
PCI .aux Labelled
Vexcel MFF Raster
Vexcel MFF2 (HKV) Raster
Fuji BAS Scanner Image
GSC Geogrid
EOSAT FAST Format
VTP .bt (Binary Terrain) 1.3 Format
Erdas .LAN/.GIS
Convair PolGASP
Image Data and Analysis
NLAPS Data Format
Erdas Imagine Raw
DIPEx
FARSITE v.4 Landscape File (.lcp)
NOAA Vertical Datum .GTX
NADCON .los/.las Datum Grid Shift
NTv2 Datum Grid Shift
ACE2
Snow Data Assimilation System
Swedish Grid RIK (.rik)
USGS Optional ASCII DEM (and CDED)
GeoSoft Grid Exchange Format
Northwood Numeric Grid Format .grd/.tab
Northwood Classified Grid Format .grc/.tab
ARC Digitized Raster Graphics
Standard Raster Product (ASRP/USRP)
Magellan topo (.blx)
SAGA GIS Binary Grid (.sdat)
Kml Super Overlay
ASCII Gridded XYZ
HF2/HFZ heightfield raster
OziExplorer Image File
USGS LULC Composite Theme Grid
Arc/Info Export E00 GRID
ZMap Plus Grid
NOAA NGS Geoid Height Grids
I have no idea about this error after searching a lot. I really appreciate that if you can give me some suggestions.
[1]: http://www.postgis.org/documentation/manual-svn/using_raster.xml.html
[2]: http://i.stack.imgur.com/YxjNJ.png

The psql utility in PostgreSQL is for processing SQL commands. The file you show doesn't contain SQL commands, it appears to contain information to help someone choose an option for the raster2pgsql program. A quick web search turned up documentation here:
http://www.postgis.org/documentation/manual-svn/using_raster.xml.html
Notice that the -G option is used to "Print the supported raster formats." The command line you used to run the program included that switch. If your goal is to produce SQL statements, that's not an option you should include. I don't know whether any other adjustments need to be made to your command, but you could start by dropping that and see what you get.

Related

How to correctly use ogr2ogr and gdal_rasterize to rasterize a smaller area of a large vector of GeoPackage?

I am using gdal_rasterize and ogr2ogr with a goal to get a partial raster of .gpkg file.
With first command I want to clip a smaller area of a large map.
ogr2ogr -spat xmin ymin xmax ymax out.gpkg in.gpkg
This results in a file that with command ogrinfo out.gpkg gives expected output by listing the layers numbers and names.
Then trying to rasterize this new file with:
gdal_rasterize out.gpkg -burn 255 -ot Byte -ts 250 250 -l anylayer out.tif
results in: ERROR 1: Cannot get layer extent when tried with any of the layers names given by ogrinfo
Using the same command on the original in.gpkg doesnt give errors and results in expected .tiff file raster.
ogr2ogr --version GDAL 2.4.2, released 2019/06/28
gdal_rasterize --version GDAL 2.4.2, released 2019/06/28
This process should at the end be implemented with the gdal C++ API.
Are the commands given some how invalid this way, how?
Should the whole process be done differently, how?
What does the ERROR 1: Cannot get layer extent mean?

Acrobat adobe can not open pdf file generated by gnuplot

I plot my data by gnuplot, then set output as pdf file.
When I use adobe to open such pdf file, it shows this error:
Adobe Acrobat Reader could not open 'Compare_E.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
Here is the plot file I used:
#!/usr/bin/gnuplot
set encoding iso_8859_1
set terminal postscript eps enhanced color font "Helvetica" 14
set output "Da.pdf"
set xr[0:1000]
set yr[0:]
set xlabel "Time (ps)"
set ylabel "Da(\305^{2})"
set key left top
plot "800/data.dat" u ($1/1000):5 w line lt 1 lw 2 lc rgb "green" title "800"
I found available term:
gnuplot> show terminal
terminal type is x11
gnuplot> set term
Available terminal types:
canvas HTML Canvas object
cgm Computer Graphics Metafile
context ConTeXt with MetaFun (for PDF documents)
domterm DomTerm terminal emulator with embedded SVG
dumb ascii art for anything that prints text
dxf dxf-file for AutoCad (default size 120x80)
emf Enhanced Metafile format
epslatex LaTeX picture environment using graphicx package
fig FIG graphics language V3.2 for XFIG graphics editor
hpgl HP7475 and relatives [number of pens] [eject]
mf Metafont plotting standard
mp MetaPost plotting standard
pcl5 PCL5e/PCL5c printers using HP-GL/2
pict2e LaTeX2e picture environment
postscript PostScript graphics, including EPSF embedded files (*.eps)
pslatex LaTeX picture environment with PostScript \specials
pstex plain TeX with PostScript \specials
pstricks LaTeX picture environment with PSTricks macros
svg W3C Scalable Vector Graphics
tek40xx Tektronix 4010 and others; most TEK emulators
tek410x Tektronix 4106, 4107, 4109 and 420X terminals
texdraw LaTeX texdraw environment
tkcanvas Tk canvas widget
unknown Unknown terminal type - not a plotting device
vttek VT-like tek40xx terminal emulator
x11 X11 Window System interactive terminal
xlib X11 Window System (dump of gnuplot_x11 command stream)
xterm Xterm Tektronix 4014 Mode
gnuplot>
Is there anyone dealing with the same error?

Using gdal compressed GeoTIFF with GeoServer

I have a big GeoTIFF that I want to stream through a WMS within GeoServer (v.2.11). The size of the image is about 7GB, consisting on a very large high resolution RGB image. I have allowed enough heap space within JVM in order to display the imagery. However, I would like to compress the image so it can be more responsive when exploring through and so it will allocate less memory. I have followed some of the recommendations here.
My strategy was to compress the GeoTIFF with JPEG compression and use that as a data store in GeoServer. However, this seems not to work. This is the gdal command I have used to translate the image:
gdal_translate -of GTiff -co "BIGTIFF=YES" -co "COMPRESS=JPEG" -co "TILED=YES" -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512" -a_srs "EPSG:3057" D:\raster\image.tif
D:\raster\image_translate.tif
When previewing the image with openlayers, I got nothing, just a blank basemap. The log from GeoServer told me that something in the projection went bad:
2017-06-09 13:16:47,551 INFO [geoserver.wms] -
Request: getServiceInfo
2017-06-09 13:16:47,561 WARN [lite.gridcoverage2d] - Could not reduce the grid geometry inside the valid area bounds: ReferencedEnvelope[-1.7976931348623157E308 : 1.7976931348623157E308, -85.0 : 85.0]
Grid geometry isGridGeometry2D[GeneralGridEnvelope[0..357, 0..357], PARAM_MT["Affine",
PARAMETER["num_row", 3],
PARAMETER["num_col", 3],
PARAMETER["elt_0_0", 0.7353351955307262],
PARAMETER["elt_0_2", 584219.1848475977],
PARAMETER["elt_1_1", -0.7353351955307262],
PARAMETER["elt_1_2", 383937.61122240225]]]
2017-06-09 13:16:47,566 ERROR [geoserver.ows] -
org.geoserver.platform.ServiceException: Error rendering coverage on the fast path
I then tried to use another compression strategy with GDAL, i.e. "DEFLATE":
gdal_translate -of GTiff -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 -co "BIGTIFF=YES" -a_srs "EPSG:3057" D:\raster\image.tif D:\raster\image_translate2.tif
And that worked when previewing in openlayers. Here is the GeoServer log:
2017-06-09 13:28:27,137 INFO [geoserver.wms] -
Request: getServiceInfo
2017-06-09 13:28:27,146 WARN [lite.gridcoverage2d] - Could not reduce the grid geometry inside the valid area bounds: ReferencedEnvelope[-1.7976931348623157E308 : 1.7976931348623157E308, -85.0 : 85.0]
Grid geometry isGridGeometry2D[GeneralGridEnvelope[0..357, 0..357], PARAM_MT["Affine",
PARAMETER["num_row", 3],
PARAMETER["num_col", 3],
PARAMETER["elt_0_0", 0.7353351955307262],
PARAMETER["elt_0_2", 584219.1848475977],
PARAMETER["elt_1_1", -0.7353351955307262],
PARAMETER["elt_1_2", 383937.61122240225]]]
2017-06-09 13:28:27,231 INFO [geoserver.wms] -
Request: getMap
I have also tried to perform gdal_translate using JPEG compression and no tiling, and I got also errors with the GeoServer log and the openlayers preview displayed nothing.
So my question is, what is the best strategy to compress GeoTIFF files to be used in a WMS? At the moment, seems that DEFLATE is the only one working, but the compression is not the best. Has anyone been able to successfully upload a JPEG compressed GeoTIFF to Geoserver?
If it's any help the way I do it is as follows.
First I chop the raster up into smaller tiles, size is not important, for me it's generally either 256x256, 512x512 or 1024x124.
I use a number of different programs from gdal2tiles.py to my own homegrown c# apps.
What's important is that the tiles are square.
Once I have the tiles in a folder, I then use gdaltindex
This creates a shapefile with one square for each tile, correctly georeferenced (assuming your raster was) along with the name of each tile, I usually tell gdaltindex to write absolute paths to the shapefile.
I then reference the shape as a tile layer in mapserver, I can't say if geoserver will accept a shape based tile index, but since gdal can make them and the other WMS based server available open source (mapserver) can use them, then I would be very suprised if geoserver was not able to use them.
This would work in the case of tiff greater than 2GB. GeoServer can efficiently deal with large TIFF with overviews, as long as the TIFF is below the 2GB size limit.
Using image pyramid makes the tiff load faster as it makes multiple mosaic of images at different zoom levels.
Use the following command:-
mkdir bmpyramid
gdal_retile.py -v -r bilinear -levels 4 -ps 2048 2048 -co "TILED=YES" -co "COMPRESS=JPEG" -targetDir bmpyramid bmreduced.tiff
You can check here
https://docs.geoserver.org/stable/en/user/tutorials/imagepyramid/imagepyramid.html

Decrease pdf-filesize in ImageMagick

I am using GIMP to convert grayscale PNM-files (scanned documents) to PDF.
My goal is a small filesize. (Ideally: viewable on different devices without any problems and maybe suitable long-term preservation - PDF/A?)
So far, so good. Trying to reproduce that process with ImageMagick in a batch script doesn't give me that same small filesize as in GIMP.
GIMP (Ver. 2.8.14) workflow:
Open File
Change resolution (density) to 300x300 Pixel/in
Set threshold to 127 (=50%)
Export as OutGIMP.pdf
ImageMagick (Ver. 6.7.9-0 2012-09-16 Q16) workflow:
convert Scan.pnm -density 300x300 -threshold 50% -monochrome OutA.pdf
convert Scan.pnm -density 300x300 -threshold 50% -monochrome OutB.png
convert OutB.png OutC.pdf
Using an example File this results in:
OutGIMP.pdf: 141.195 Byte
OutA.pdf: 684.245 Byte
OutB.png: 137.246 Byte
OutC.pdf: 217.860 Byte
How can I get a PDF with ImageMagick that is at least as small as the GIMP-PDF?
Edit
Continuing the GIMP (Ver. 2.8.14) workflow from above with:
Scale to 100x100 Pixel/in while keeping the Imagesize
Export as OutGIMP_100ppi.pdf
strangely results in:
OutGIMP_100ppi.pdf: 179.123 Byte

Display Shapefiles .shp areas and markers on Google Maps API?

I have some Shapefiles displaying areas and others displaying points on the map, I want to use those on my web application and use Google Maps API. How do I do that?
I've tried converting them to more managable .kml files, but I can't do it because there are no coordinates in the .dbf file (checked using Excel). I'm stuck now. Thanks.
As geocodezip already suggests, for the bike_sharing_places you could use ogr2ogr like this:
ogr2ogr -f KML bike_sharing_places.kml BIKE_SH.shp -t_srs EPSG:4326 -s_srs EPSG:3003
This converts your shapefile to KML and reprojects from your projection (Monte_Mario_Italy_zone_1 EPSG:3003) to WGS84 (EPSG:4326), which is required for Google Maps.
In your other file (dogs_park) the file with projection information is missing. I took a guess, and it appears to be in UTM 32N (EPSG:32632). So you first have to assign that projection.
ogr2ogr -a_srs EPSG:32632 aree_fruizione_cani_UTM.shp aree_fruizione_cani.shp
Then convert and reproject:
ogr2ogr -f KML dogs_park.kml aree_fruizione_cani_UTM.shp -t_srs EPSG:4326 -s_srs EPSG:32632