<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<span>Thanks Mike,</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
I found the problem. </div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
When I call CreateLayer() I am passing the SRS but if I try to print it just before calling RasterizeLayer(), it is not there.</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
I tried to call FlushCache() and SyncToDisk() but the only thing that solve the problem is to close the dataset and open it again.</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> geom_ds
= ogr.GetDriverByName('GEOJSON').CreateDataSource('E:\TMP\MEMORY_%s.JSON' % name)</span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><br>
</span><span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> geom_lyr
= geom_ds.CreateLayer('MEMORY_LAYER', geom_type=ogr.wkbPolygon, <b>srs=ref_srs</b>)</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
</span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">geom_feat
= ogr.Feature(geom_lyr.GetLayerDefn())</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> geom_feat.SetGeometry(geom)</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> </span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
geom_lyr.CreateFeature(geom_feat)</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><br>
</span></div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span>
geom_ds.FlushCache() # That doesn't <br>
</span>
<div> geom_ds.SyncToDisk() # help</div>
<span></span><br>
</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> mem_ds
= gdal.GetDriverByName('GTIFF').Create('E:\TMP\MEMORY_%s.TIF' % name, xcount, ycount, 1, gdal.GDT_Byte)</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> mem_ds.SetGeoTransform((</span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">xmin,
xResolut, 0, </span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">ymax,
0, yResolut,</span><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">))</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> mem_ds.SetProjection(ref_ds.GetProjectionRef())</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> mem_ds.FlushCache()</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> </span></div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span><span style="background-color: rgb(255, 255, 255); border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; display: inline; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
print(</span><span style="display: inline !important; background-color: rgb(255, 255, 255); font-size-adjust: none">geom_lyr.GetSpatialRef()) # None!!</span></span></span></div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span><br style="font-family: Courier New,monospace">
# That's the solution: close and open the dataset again</span></span></div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span><span style="display: inline !important; background-color: rgb(255, 255, 255); font-size-adjust: none">
</span>geom_ds = None<br>
</span>
<div> geom_ds = ogr.Open('E:\TMP\MEMORY_%s_GEOM.JSON' % name)</div>
<div><span> geom_lyr = geom_ds.GetLayerByName('MEMORY_LAYER')</span></div>
<div><span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
# todo: how can I do that in memory?</span></span></div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<br>
</div>
</span></div>
<div>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"><span style="background-color: rgb(255, 255, 255); border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; display: inline; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
print(</span><span style="background-color: rgb(255, 255, 255); border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; display: inline; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">geom_lyr.GetSpatialRef())
# Good!!</span></span></span></div>
<br>
</div>
</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> err =
gdal.RasterizeLayer(mem_ds, [1], geom_lyr, burn_values=[1])</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> if err
!= 0:</span></div>
<span style="display: inline !important; background-color: rgb(255, 255, 255); color: black; font-family: Calibri,Helvetica,sans-serif; font-size: 12pt; font-size-adjust: none"></span>
<div style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px">
<span style="border-bottom-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-top-color: currentColor; font-family: Courier New,monospace; font-size-adjust: none; margin-bottom: 0px; margin-top: 0px"> print(err)</span></div>
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
Even, does it look like a bug to you? A GEOJSON driver bug maybe. I probably did something like that once in a raster driver, wait for the closing of the file to update the SRS. </div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
Thanks,</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<span title=""><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<span title="">Ivan</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Mike Taves <mwtoews@gmail.com><br>
<b>Sent:</b> Wednesday, July 24, 2019 4:40 PM<br>
<b>To:</b> Ivan Lucena <ivan.lucena@outlook.com><br>
<b>Cc:</b> gdal-dev@lists.osgeo.org <gdal-dev@lists.osgeo.org><br>
<b>Subject:</b> Re: [gdal-dev] Python RasterizeLayer and gdal_rasterize</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">On Thu, 25 Jul 2019 at 01:19, Ivan Lucena <ivan.lucena@outlook.com> wrote:<br>
> mem_ds.SetGeoTransform((xmin, xResolut, 0, ymax, 0, yResolut,))<br>
<br>
Check your value for yResolut, as it should be negative. In my<br>
experience, a raster full of zeros is when the geometry is outside the<br>
raster window, so be sure to manually check the raster and vector<br>
geometries in (e.g.) QGIS. Lastly, to properly close the file, you<br>
only need to dereference the object:<br>
<br>
mem_ds = None<br>
</div>
</span></font></div>
</body>
</html>