Gdal Polygonize Java

المشرف العام

Administrator
طاقم الإدارة
I tried to use the gdalPolygonize function within in java. What I did


  1. Installed gdal-111-1800-x64-core from the following link (http://www.gisinternals.com/query.h...ease-1800-x64-gdal-1-11-1-mapserver-6-4-1.zip)
  2. Created a new Java Project and added the jar file from the in C:\Program Files\GDAL\java to the java project
After that I tried to run that code. It works so fine I get no errors. But opening the shapefile in Qgis it's blank. What am I doing wrong?

import org.gdal.gdal.Band; import org.gdal.gdal.Dataset; import org.gdal.gdal.gdal; import org.gdal.gdalconst.gdalconstConstants; import org.gdal.ogr.*; import org.gdal.osr.SpatialReference; import org.gdal.osr.osr; public class main { public static void main(String[] args) { // TODO Auto-generated method stub String[] temp = {"abia.tif"}; gdalPolygonize(temp); } public static void gdalPolygonize(String[] args) { gdal.AllRegister(); ogr.RegisterAll(); args = gdal.GeneralCmdLineProcessor(args); Dataset hDataset = gdal.Open(args[0], gdalconstConstants.GA_ReadOnly); SpatialReference srs = new SpatialReference(); if(!hDataset.GetProjectionRef().isEmpty()) srs.ImportFromWkt(hDataset.GetProjectionRef()); Band rasterBand = hDataset.GetRasterBand(1); Driver driver = ogr.GetDriverByName("ESRI Shapefile"); DataSource dataSource = driver.CreateDataSource("C:\\Users\\Michael\\Desktop\\destination.shp"); Layer outputLayer = dataSource.CreateLayer("destination", srs); FieldDefn field_def = new FieldDefn("DN",4); outputLayer.CreateField(field_def); gdal.Polygonize(rasterBand, null, outputLayer, 0); } }

أكثر...
 
أعلى