<div dir="ltr">I am now trying to do this process as an in-memory process.<div>I coudl figure out how to load the .tif in-memory :</div><div><br></div><div><div> # Create in-memory file and initialize it with the content<br></div><div>gdal.FileFromMemBuffer('/vsimem/tiffinmem', self.file)</div><div><br></div><div># Open the in-memory file</div><div>ds = gdal.Open('/vsimem/tiffinmem', gdal.GA_Update)</div></div><div><br></div><div>But i've got some problem to get a </div><div><span style="font-size:12.8px"><osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' </span></div><div><span style="font-size:12.8px">from</span> a geojson... Here are my vain attemps:</div><div><br></div><div><br></div><div> #create an output datasource in memory</div><div>outdriver=ogr.GetDriverByName('MEMORY')</div><div>source=outdriver.CreateDataSource('memData')</div><div># <osgeo.ogr.DataSource; proxy of <Swig Object of type 'OGRDataSourceShadow *'</div><div>#open the memory datasource with write access</div><div>tmp=outdriver.Open('memData',1)</div><div><br></div><div><div>import os</div><div>import sys</div><div>from osgeo import gdal, ogr, osr</div></div><div>geojson = """{"type":"Polygon","coordinates":[[[-76.4603750,45.4506926],[-76.4603632,45.4506998],[-76.4603522,45.4506914],[-76.4603639,45.4506845],[-76.4603750,45.4506926]]]}"""</div><div>geometry = ogr.CreateGeometryFromJson(geojson)</div><div># print type(geometry)</div><div># <class 'osgeo.ogr.Geometry'><br></div><div><br></div><div>I know that i need to build a <span style="font-size:12.8px">GDALDatasetShadow object from the </span>OGRDataSourceShadow object and the osgeo.ogr.Geometry object but i've got no clue after searching on the web :</div><div><a href="http://www.gdal.org/classGDALDataset.html#a9cb8585d0b3c16726b08e25bcc94274a">http://www.gdal.org/classGDALDataset.html#a9cb8585d0b3c16726b08e25bcc94274a</a><br></div><div><a href="https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#load-data-to-memory">https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#load-data-to-memory</a><br></div><div><a href="https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#spatial-filter">https://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html#spatial-filter</a><br></div><div><br></div><div>Could please give a hint ?</div><div><br></div><div>I would be grateful.</div><div><br></div><div>Cheers</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><br>François ALLAIN<br>+33 651399906<br><br></div></div></div></div></div></div></div></div>
<br><div class="gmail_quote">On Fri, Jul 15, 2016 at 9:45 AM, François ALLAIN <span dir="ltr"><<a href="mailto:frallain@gmail.com" target="_blank">frallain@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">My bad... I finally got it working with your code :</div><div class="gmail_extra"><br></div><div class="gmail_extra"><span class=""><div class="gmail_extra">import os</div><div class="gmail_extra">import sys</div><div class="gmail_extra">from osgeo import gdal, ogr, osr<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">geojson_filename = "my.geojson"</div><div class="gmail_extra">driver = ogr.GetDriverByName("GeoJSON")</div></span><div class="gmail_extra">vector_ds = gdal.OpenEx( geojson_filename, gdal.OF_VECTOR )</div><span class=""><div class="gmail_extra"><br></div><div class="gmail_extra">geotiff_filename = "my.tif"</div><div class="gmail_extra">ds = gdal.Open(geotiff_filename, gdal.GA_Update)</div><div class="gmail_extra"><br></div><div class="gmail_extra">ret = gdal.Rasterize(ds,</div><div class="gmail_extra"> vector_ds,</div><div class="gmail_extra"> bands = [4],</div><div class="gmail_extra"> inverse = True,</div><div class="gmail_extra"> burnValues = [0])</div><div class="gmail_extra"><br></div><div class="gmail_extra">if ret != 1:</div><div class="gmail_extra"> print 'fail'</div><div class="gmail_extra">else:</div><div class="gmail_extra"> print 'success'</div><div><br></div></span><div>Cheers and thanks again</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>François</div><div><br></div><div><br></div></font></span></div></div>
</blockquote></div><br></div>