Specifying extent in GDAL WriteArray?
Is it possible to specify the extent when creating an empty raster in GDAL?
I looked everywhere, but can't seem to find anything. The portion of my script where I write the raster would look something like this:
tifpath = "path/to/output/tiff.tif" drvtif = gdal.GetDriverByName("GTiff") rast = drvtif.Create(tifpath, Ncolumns, Nrows, Nbands, datatype) rast.SetProjection(projection) # projection being a variable representing the desired projection rast.GetRasterBand(1).WriteArray(array)
My array is an array of size Ncolumns x Nrows, filled with 0's (I want an empty raster). The number of pixels is predetermined, as is the cell size, and by multiplying npixels*cellsize, I've determined what my output extents need to be such that each pixel is a whole pixel (i.e. doesn't get cut off by the extent).
But, I can't find any options that would allow me to specify the desired extent.
It's also just occurred to me that I don't see any option to specify cell size.
Yes, using the
SetGeoTransformmethod. The Geographic Transform defines the origin of the raster in the upper left hand corner, as well as the cell size and the rotation in the x and y direction for the cells in this format:
geo_transform = (x top left, x cell size, x rotation, y top left, y rotation, negative y cell size)
Or in the example you've supplied:
geo_transform = (-180, 0.0089952083, 0., 90, 0., -0.0089952083)
This can set be applied to the dataset object;
Note The top left will be the coordinates of the top left of the cell, not the cell centre.
Working with ECOSTRESS Evapotranspiration Data
The Land Processes Distributed Active Archive Center (LP DAAC) distributes the Ecosystem Spaceborne Thermal Radiometer Experiment on Space Station (ECOSTRESS) data products. The ECOSTRESS mission is tasked with measuring the temperature of plants to better understand how much water plants need and how they respond to stress. ECOSTRESS products are archived and distributed in the HDF5 file format as swath-based products.
In this tutorial, you will use Python to perform a swath to grid conversion to project the swath data on to a grid with a defined coordinate reference system (CRS), compare ECOSTRESS data with ground-based AmeriFlux flux tower observations, and export science dataset (SDS) layers as GeoTIFF files that can be loaded into a GIS and/or Remote Sensing software program.
Example: Converting a swath ECO3ETPTJPL.001 HDF5 file into a GeoTIFF with a defined CRS and comparing ECOSTRESS Evapotranspiration (ET) with ground-based ET observations from an AmeriFlux flux tower location in California.
Data Used in the Example:
- Data Product: ECOSTRESS Evapotranspiration PT-JPL Daily L3 Global 70m Version 1 (ECO3ETPTJPL.001)
- Science Dataset (SDS) layers:
- Science Dataset (SDS) layers:
- Latent Heat (W/m 2 )
If a crime applies extraterritorially under the Special Maritime and Territorial Jurisdiction, can it be applied when committed in a foreign country?
I’ve been finding this confusing. If Bob, a US citizen, commits a crime in country A, which is illegal extraterritorially under the Special Maritime & Territorial Jurisdiction, does this mean he can be indicted by the US for it? By my reading from here, the answer is no, as a foreign country does not seem to be included in the definition of the SMTJ. The Special Maritime and Territorial Jurisdiction is defined as:
The term “special maritime and territorial jurisdiction of the United States”, as used in this title, includes:
(1) The high seas, any other waters within the admiralty and maritime jurisdiction of the United States and out of the jurisdiction of any particular State, and any vessel belonging in whole or in part to the United States or any citizen thereof, or to any corporation created by or under the laws of the United States, or of any State, Territory, District, or possession thereof, when such vessel is within the admiralty and maritime jurisdiction of the United States and out of the jurisdiction of any particular State.
(2) Any vessel registered, licensed, or enrolled under the laws of the United States, and being on a voyage upon the waters of any of the Great Lakes, or any of the waters connecting them, or upon the Saint Lawrence River where the same constitutes the International Boundary Line.
(3) Any lands reserved or acquired for the use of the United States, and under the exclusive or concurrent jurisdiction thereof, or any place purchased or otherwise acquired by the United States by consent of the legislature of the State in which the same shall be, for the erection of a fort, magazine, arsenal, dockyard, or other needful building.
(4) Any island, rock, or key containing deposits of guano, which may, at the discretion of the President, be considered as appertaining to the United States.
(5) Any aircraft belonging in whole or in part to the United States, or any citizen thereof, or to any corporation created by or under the laws of the United States, or any State, Territory, District, or possession thereof, while such aircraft is in flight over the high seas, or over any other waters within the admiralty and maritime jurisdiction of the United States and out of the jurisdiction of any particular State.
(6) Any vehicle used or designed for flight or navigation in space and on the registry of the United States pursuant to the Treaty on Principles Governing the Activities of States in the Exploration and Use of Outer Space, Including the Moon and Other Celestial Bodies and the Convention on Registration of Objects Launched into Outer Space, while that vehicle is in flight, which is from the moment when all external doors are closed on Earth following embarkation until the moment when one such door is opened on Earth for disembarkation or in the case of a forced landing, until the competent authorities take over the responsibility for the vehicle and for persons and property aboard.
(7) Any place outside the jurisdiction of any nation with respect to an offense by or against a national of the United States.
(8) To the extent permitted by international law, any foreign vessel during a voyage having a scheduled departure from or arrival in the United States with respect to an offense committed by or against a national of the United States.
(9) With respect to Offenses committed by or against a national of the United States as that term is used in section 101 of the Immigration and Nationality Act—
(A) the premises of United States diplomatic, consular, military or other United States Government missions or entities in foreign States, including the buildings, parts of buildings, and land appurtenant or ancillary thereto or used for purposes of those missions or entities, irrespective of ownership and
(B) residences in foreign States and the land appurtenant or ancillary thereto, irrespective of ownership, used for purposes of those missions or entities or used by United States personnel assigned to those missions or entities.
Fast tip: Changing the geotransform with GDAL python
Preparing the next post, I have found a file with a wrong geotransform, but not an easy tool to do it.
Coding it is as easy as opening the datasource with the update option and setting the new geotransform as follows:
Where the geotransform must be a tuple like (-180.5, 1.0, 0.0, 90.5, 0.0, -1.0). Take a look to the documentation for more information.
I have created a small program to make it even easier, called changeGeotransform.py:
The nice part of the app is the moving compass. To get it, we need three things:
- Getting the geograpgical coordinates
- Getting the device orientation (the geographical one) and the screen orientation (landscape or portrait)
- Drawing the data
Getting the location is quite standard, just listening to navigator.geolocation.watchPosition and calling a callback. The browser will ask for permission.
The orientation seemed easy too, but it’s not. I found a compass example (with an error, always points to the initial device position) but many browsers require special configurations to allow the orientation to be read.
The event to listen to is window.addEventListener("deviceorientationabsolute", setHeading) (not a navigator event!?). And it’s using a callback too. In this case, an angle has to be added if the device is in landscape mode (and it can have two positions in landscape mode). The screen orientation lives in the screen object.
Again, Svelte makes really easy everything. If something in the function arguments change, the function is called. It’s like the useEffect in react, but better!
The same hapens to fire the fetch data function. If amenity , lon or lat change, the code is run again.
To draw the data, I separated the code to a function drawCompass with its own file draw-compass.ts . The funtion uses the typical functions for canvas, so I won’t copy all the code here.
This web is a clear candidate to become a PWA since it’s much better on a mobile device that has orientation sensor. To do it I found a single example in Svelte.
The first thing was adding the following line to public/index.html :
<link rel=’manifest’ href=’manifest.json’>
And create the manifest.json file in the same folder:
Some lines seem unnecessary but if they are not there, the browser won’t allow the user to save the app on the desktop.
The next step is adding the service worker. This is also necessary. It must have the fetch method, that many times is omitted.
- Be careful with the paths on the cache! If something fails, the service worker is not installed.
- There’s a dedicated section to check that in the dev tools (first two on the application tab)
Once this is done, the site must listen to the beforeunnstallprompt event:
Once the event is stored, it’s possible to call it when clicking a button. Here the function to prepare and the one that actually installs:
- Unistall app before trying again! I was stuck on this and it’s really frustrating because nothing happens and it’s difficult to know why… To uninstall, open the app and click on the second icon at the top when in a computer.
- If the handleInstall function is not logging anything, check the dev tools for some tip.
- btnInstallAppVisible is the variable that hides the button when the app is installed and the button is not needed anymore.
重新投影栅格数据 ( Reprojecting raster data )
Reprojection means to find a new representation for your raster data based on a different crs (i.e., other coordinate system), a different transform (e.g., to rotate the raster), or different bounds. This may include rotations and distortions, making reprojections rather complex
The following code simply reprojects the given dataset into a new crs ( new_crs ) with any alterations to the underlying transformation. The code reads in a dataset, derives a new transformation, raster height and width, creates an array for the reprojected data ( new_imgdata ) and finally performs the reprojection:
以下代码仅将给定的数据集重新投影到新的crs( new_crs )中，并且对基础转换进行了任何更改。 该代码读取数据集，得出新的变换，栅格高度和宽度，为重新投影的数据( new_imgdata )创建一个数组，最后执行重新投影：
性能比较 ( Performance Comparison )
How does the GeoTIFF.js query logic stack up against a call to gdallocationinfo ? This can depend a bit on how many files you are opening (especially repeatedly), but my results, both experimentally and in practice, have been decisive. On a solid state drive, I queried the same raster (about 500px by 200px, with 250 bands) using the same latitude and longitude and recorded the elapsed milliseconds.
如何将GeoTIFF.js查询逻辑与对 gdallocationinfo 的调用进行 gdallocationinfo ？ 这可能取决于您打开的文件数量(尤其是重复打开的文件数量)，但是我的实验和实践结果都是决定性的。 在固态驱动器上，我使用相同的纬度和经度查询了相同的栅格(大约500px x 200px，具有250条带)，并记录了经过的毫秒数。
exec(gdallocationinfo . )
This method seems to experience random hiccups every few runs that are detrimental to its overall processing time. This has been noted across my development computer in addition to my servers.
Not only was this library slightly quicker than a call to gdallocationinfo , performance was very consistent, nearly halving the average processing time.
- Science Dataset (SDS) layers: