Skip to content

Commit

Permalink
EEDA: fix startTime / endTime comparisons that were incomplete in refs
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed May 11, 2019
1 parent def8303 commit 3506884
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
2 changes: 1 addition & 1 deletion autotest/gdrivers/eedai.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def test_eedai_real_service():
ds = gdal.Open('EEDAI:USDA/NAIP/DOQQ/n_4010064_se_14_2_20070725')
assert ds is not None
res = gdal.Info(ds, format='json')
expected = {'files': [], 'cornerCoordinates': {'upperRight': [415016.0, 4435536.0], 'lowerLeft': [408970.0, 4427936.0], 'lowerRight': [415016.0, 4427936.0], 'upperLeft': [408970.0, 4435536.0], 'center': [411993.0, 4431736.0]}, 'wgs84Extent': {'type': 'Polygon', 'coordinates': [[]]}, 'description': 'EEDAI:USDA/NAIP/DOQQ/n_4010064_se_14_2_20070725', 'driverShortName': 'EEDAI', 'driverLongName': 'Earth Engine Data API Image', 'bands': [{'description': 'R', 'band': 1, 'colorInterpretation': 'Red', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}, {'description': 'G', 'band': 2, 'colorInterpretation': 'Green', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}, {'description': 'B', 'band': 3, 'colorInterpretation': 'Blue', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}], 'coordinateSystem': {'wkt': 'PROJCS["NAD83 / UTM zone 14N",\n GEOGCS["NAD83",\n DATUM["North_American_Datum_1983",\n SPHEROID["GRS 1980",6378137,298.257222101,\n AUTHORITY["EPSG","7019"]],\n TOWGS84[0,0,0,0,0,0,0],\n AUTHORITY["EPSG","6269"]],\n PRIMEM["Greenwich",0,\n AUTHORITY["EPSG","8901"]],\n UNIT["degree",0.0174532925199433,\n AUTHORITY["EPSG","9122"]],\n AUTHORITY["EPSG","4269"]],\n PROJECTION["Transverse_Mercator"],\n PARAMETER["latitude_of_origin",0],\n PARAMETER["central_meridian",-99],\n PARAMETER["scale_factor",0.9996],\n PARAMETER["false_easting",500000],\n PARAMETER["false_northing",0],\n UNIT["metre",1,\n AUTHORITY["EPSG","9001"]],\n AXIS["Easting",EAST],\n AXIS["Northing",NORTH],\n AUTHORITY["EPSG","26914"]]'}, 'geoTransform': [408970.0, 2.0, 0.0, 4435536.0, 0.0, -2.0], 'metadata': {'IMAGE_STRUCTURE': {'INTERLEAVE': 'PIXEL'}}, 'size': [3023, 3800]}
expected = {'files': [], 'cornerCoordinates': {'upperRight': [415016.0, 4435536.0], 'lowerLeft': [408970.0, 4427936.0], 'lowerRight': [415016.0, 4427936.0], 'upperLeft': [408970.0, 4435536.0], 'center': [411993.0, 4431736.0]}, 'wgs84Extent': {'type': 'Polygon', 'coordinates': [[[-100.067433, 40.0651671], [-100.0663662, 39.9967049], [-99.9955511, 39.9973349], [-99.9965471, 40.0657986], [-100.067433, 40.0651671]]]}, 'description': 'EEDAI:USDA/NAIP/DOQQ/n_4010064_se_14_2_20070725', 'driverShortName': 'EEDAI', 'driverLongName': 'Earth Engine Data API Image', 'bands': [{'description': 'R', 'band': 1, 'colorInterpretation': 'Red', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}, {'description': 'G', 'band': 2, 'colorInterpretation': 'Green', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}, {'description': 'B', 'band': 3, 'colorInterpretation': 'Blue', 'overviews': [{'size': [1511, 1900]}, {'size': [755, 950]}, {'size': [377, 475]}, {'size': [188, 237]}], 'type': 'Byte', 'block': [256, 256], 'metadata': {}}], 'coordinateSystem': {'wkt': 'PROJCS["NAD83 / UTM zone 14N",\n GEOGCS["NAD83",\n DATUM["North_American_Datum_1983",\n SPHEROID["GRS 1980",6378137,298.257222101,\n AUTHORITY["EPSG","7019"]],\n TOWGS84[0,0,0,0,0,0,0],\n AUTHORITY["EPSG","6269"]],\n PRIMEM["Greenwich",0,\n AUTHORITY["EPSG","8901"]],\n UNIT["degree",0.0174532925199433,\n AUTHORITY["EPSG","9122"]],\n AUTHORITY["EPSG","4269"]],\n PROJECTION["Transverse_Mercator"],\n PARAMETER["latitude_of_origin",0],\n PARAMETER["central_meridian",-99],\n PARAMETER["scale_factor",0.9996],\n PARAMETER["false_easting",500000],\n PARAMETER["false_northing",0],\n UNIT["metre",1,\n AUTHORITY["EPSG","9001"]],\n AXIS["Easting",EAST],\n AXIS["Northing",NORTH],\n AUTHORITY["EPSG","26914"]]'}, 'geoTransform': [408970.0, 2.0, 0.0, 4435536.0, 0.0, -2.0], 'metadata': {'IMAGE_STRUCTURE': {'INTERLEAVE': 'PIXEL'}}, 'size': [3023, 3800]}
assert expected == res
assert ds.ReadRaster(0, 0, 1, 1) is not None

Expand Down
13 changes: 7 additions & 6 deletions autotest/ogr/ogr_eeda.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def test_eeda_2():

lyr.SetAttributeFilter(None)
lyr.SetAttributeFilter("startTime >= '1980-01-01T00:00:00Z' AND " +
"startTime <= '2100-01-01T00:00:00Z' AND " +
"string_field = 'bar' AND " +
"int_field > 0 AND " +
"int_field < 2 AND " +
Expand All @@ -220,7 +219,7 @@ def test_eeda_2():
"string_field IN ('bar', 'baz') AND " +
"NOT( int_field IN (0) OR double_field IN (3.5) )")

ogrtest.eeda_drv_tmpfile = '/vsimem/ee/projects/earthengine-public/assets/collection:listImages?region=%7B%20%22type%22%3A%20%22Polygon%22%2C%20%22coordinates%22%3A%20%5B%20%5B%20%5B%20%2D180%2E0%2C%20%2D90%2E0%20%5D%2C%20%5B%20%2D180%2E0%2C%2090%2E0%20%5D%2C%20%5B%20180%2E0%2C%2090%2E0%20%5D%2C%20%5B%20180%2E0%2C%20%2D90%2E0%20%5D%2C%20%5B%20%2D180%2E0%2C%20%2D90%2E0%20%5D%20%5D%20%5D%20%7D&filter=%28%28%28%28%28%28%28string%5Ffield%20%3D%20%22bar%22%20AND%20int%5Ffield%20%3E%200%29%20AND%20int%5Ffield%20%3C%202%29%20AND%20int64%5Ffield%20%3E%3D%200%29%20AND%20int64%5Ffield%20%3C%3D%209999999999999%29%20AND%20double%5Ffield%20%21%3D%203%2E5%29%20AND%20string%5Ffield%20%3D%20%22bar%22%20OR%20string%5Ffield%20%3D%20%22baz%22%29%20AND%20%28NOT%20%28int%5Ffield%20%3D%200%20OR%20double%5Ffield%20%3D%203%2E5%29%29%29&startTime=1980%2D01%2D01T00%3A00%3A00Z&endTime=2100%2D01%2D01T00%3A00%3A00Z'
ogrtest.eeda_drv_tmpfile = '/vsimem/ee/projects/earthengine-public/assets/collection:listImages?region=%7B%20%22type%22%3A%20%22Polygon%22%2C%20%22coordinates%22%3A%20%5B%20%5B%20%5B%20%2D180%2E0%2C%20%2D90%2E0%20%5D%2C%20%5B%20%2D180%2E0%2C%2090%2E0%20%5D%2C%20%5B%20180%2E0%2C%2090%2E0%20%5D%2C%20%5B%20180%2E0%2C%20%2D90%2E0%20%5D%2C%20%5B%20%2D180%2E0%2C%20%2D90%2E0%20%5D%20%5D%20%5D%20%7D&filter=%28%28%28%28%28%28%28string%5Ffield%20%3D%20%22bar%22%20AND%20int%5Ffield%20%3E%200%29%20AND%20int%5Ffield%20%3C%202%29%20AND%20int64%5Ffield%20%3E%3D%200%29%20AND%20int64%5Ffield%20%3C%3D%209999999999999%29%20AND%20double%5Ffield%20%21%3D%203%2E5%29%20AND%20string%5Ffield%20%3D%20%22bar%22%20OR%20string%5Ffield%20%3D%20%22baz%22%29%20AND%20%28NOT%20%28int%5Ffield%20%3D%200%20OR%20double%5Ffield%20%3D%203%2E5%29%29%29&startTime=1980%2D01%2D01T00%3A00%3A00Z'
gdal.FileFromMemBuffer(ogrtest.eeda_drv_tmpfile, json.dumps({
'images': [
{
Expand Down Expand Up @@ -254,14 +253,15 @@ def test_eeda_2():
lyr.SetSpatialFilter(None)

# Test time equality with second granularity
lyr.SetAttributeFilter("startTime = '1980-01-01T00:00:00Z'")
lyr.SetAttributeFilter("startTime >= '1980-01-01T00:00:00Z' AND endTime <= '1980-01-02T23:59:00Z'")

ogrtest.eeda_drv_tmpfile = '/vsimem/ee/projects/earthengine-public/assets/collection:listImages?startTime=1980%2D01%2D01T00%3A00%3A00Z&endTime=1980%2D01%2D01T00%3A00%3A01Z'
gdal.FileFromMemBuffer(ogrtest.eeda_drv_tmpfile, json.dumps({
'images': [
{
'name': 'projects/earthengine-public/assets/collection/filtered_feature',
'startTime': '1980-01-01T00:00:00Z'
'startTime': '1980-01-01T00:00:00Z',
'endTime': '1980-01-02T23:59:59Z'
},
{
'name': 'projects/earthengine-public/assets/collection/second_feature'
Expand All @@ -275,14 +275,15 @@ def test_eeda_2():
assert f.GetField('name') == 'projects/earthengine-public/assets/collection/filtered_feature'

# Test time equality with day granularity
lyr.SetAttributeFilter("startTime = '1980-01-01'")
lyr.SetAttributeFilter("startTime = '1980-01-01' AND endTime = '1980-01-02'")

ogrtest.eeda_drv_tmpfile = '/vsimem/ee/projects/earthengine-public/assets/collection:listImages?startTime=1980%2D01%2D01T00%3A00%3A00Z&endTime=1980%2D01%2D01T23%3A59%3A59Z'
ogrtest.eeda_drv_tmpfile = '/vsimem/ee/projects/earthengine-public/assets/collection:listImages?startTime=1980%2D01%2D01T00%3A00%3A00Z&endTime=1980%2D01%2D02T23%3A59%3A59Z'
gdal.FileFromMemBuffer(ogrtest.eeda_drv_tmpfile, json.dumps({
'images': [
{
'name': 'projects/earthengine-public/assets/collection/filtered_feature',
'startTime': '1980-01-01T12:00:00Z',
'endTime': '1980-01-02T23:59:59Z'
},
{
'name': 'projects/earthengine-public/assets/collection/second_feature'
Expand Down
5 changes: 3 additions & 2 deletions gdal/frmts/eeda/drv_eeda.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ <h2>Attributes</h2>
<tr><td>id</td><td>String</td><td>Image ID; equivalent to name without the "projects/*/assets/" prefix (e.g. users/USER/ASSET)</td><td>No</td></tr>
<tr><td>path</td><td>String</td><td>(Deprecated) Image path; equivalent to id</td><td>No</td></tr>
<tr><td>gdal_dataset</td><td>String</td><td>GDAL dataset name (e.g. EEDAI:projects/earthengine-public/assets/COPERNICUS/S2/20170430T190351_20170430T190351_T10SEG)<br/>that can be opened with the <a href="frmt_eedai.html">Google Earth Engine Data API Image driver</a></td><td>No</td></tr>
<tr><td>time</td><td>DateTime</td><td>Acquisition date</td><td><b>Yes</b></td></tr>
<tr><td>startTime</td><td>DateTime</td><td>Acquisition start date</td><td><b>Yes (restricted to &gt;= comparison on top level)</b></td></tr>
<tr><td>endTime</td><td>DateTime</td><td>Acquisition end date</td><td><b>Yes (restricted to &lt;= comparison on top level)</b></td></tr>
<tr><td>updateTime</td><td>DateTime</td><td>Update date</td><td>No</td></tr>
<tr><td>sizeBytes</td><td>Integer64</td><td>File size in bytes</td><td>No</td></tr>
<tr><td>band_count</td><td>Integer</td><td>Number of bands</td><td>No</td></tr>
Expand Down Expand Up @@ -154,7 +155,7 @@ <h3>Examples</h3>
<li>
Listing all images available matching criteria :
<pre>
ogrinfo -ro -al "EEDA:projects/earthengine-public/assets/COPERNICUS/S2" -where "time &gt;= '2015/03/26 00:00:00' AND CLOUDY_PIXEL_PERCENTAGE &lt; 10" --config EEDA_CLIENT_EMAIL "my@email" --config EEDA_PRIVATE_KEY_FILE my.pem
ogrinfo -ro -al "EEDA:projects/earthengine-public/assets/COPERNICUS/S2" -where "startTime &gt;= '2015/03/26 00:00:00' AND endTime &lt;= '2015/06/30 00:00:00' AND CLOUDY_PIXEL_PERCENTAGE &lt; 10" --config EEDA_CLIENT_EMAIL "my@email" --config EEDA_PRIVATE_KEY_FILE my.pem
</pre>
<p>

Expand Down
80 changes: 43 additions & 37 deletions gdal/frmts/eeda/eedadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,55 +793,61 @@ CPLString GDALEEDALayer::BuildFilter(swq_expr_node* poNode, bool bIsAndTopLevel)
else if( bIsAndTopLevel &&
poNode->eNodeType == SNT_OPERATION &&
(poNode->nOperation == SWQ_EQ ||
poNode->nOperation == SWQ_GE ||
poNode->nOperation == SWQ_LE) &&
poNode->nOperation == SWQ_GE) &&
poNode->nSubExprCount == 2 &&
poNode->papoSubExpr[0]->eNodeType == SNT_COLUMN &&
poNode->papoSubExpr[1]->eNodeType == SNT_CONSTANT &&
poNode->papoSubExpr[0]->field_index ==
m_poFeatureDefn->GetFieldIndex("startTime") &&
poNode->papoSubExpr[1]->field_type == SWQ_TIMESTAMP )
{
if( poNode->nOperation == SWQ_GE || poNode->nOperation == SWQ_EQ )
int nTerms = GDALEEDALayerParseDateTime(poNode->papoSubExpr[1]->string_value,
SWQ_GE,
nYear, nMonth, nDay, nHour, nMinute, nSecond);
if( nTerms >= 3 )
{
int nTerms = GDALEEDALayerParseDateTime(poNode->papoSubExpr[1]->string_value,
SWQ_GE,
nYear, nMonth, nDay, nHour, nMinute, nSecond);
if( nTerms >= 3 )
{
m_osStartTime = CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
nYear, nMonth, nDay, nHour, nMinute, nSecond);
}
else
{
m_bFilterMustBeClientSideEvaluated = true;
}
m_osStartTime = CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
nYear, nMonth, nDay, nHour, nMinute, nSecond);
}
if( poNode->nOperation == SWQ_LE || poNode->nOperation == SWQ_EQ )
else
{
int nTerms = GDALEEDALayerParseDateTime(poNode->papoSubExpr[1]->string_value,
SWQ_LE,
nYear, nMonth, nDay, nHour, nMinute, nSecond);
if( nTerms >= 3 )
{
if( poNode->nOperation == SWQ_EQ && nTerms == 6 )
{
if( nSecond < 59 )
nSecond ++;
else if( nMinute < 59 )
nMinute ++;
else if( nHour < 23 )
nHour ++;
else
nDay ++;
}
m_osEndTime = CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
nYear, nMonth, nDay, nHour, nMinute, nSecond);
}
else
m_bFilterMustBeClientSideEvaluated = true;
}
return "";
}
else if( bIsAndTopLevel &&
poNode->eNodeType == SNT_OPERATION &&
(poNode->nOperation == SWQ_EQ ||
poNode->nOperation == SWQ_LE) &&
poNode->nSubExprCount == 2 &&
poNode->papoSubExpr[0]->eNodeType == SNT_COLUMN &&
poNode->papoSubExpr[1]->eNodeType == SNT_CONSTANT &&
poNode->papoSubExpr[0]->field_index ==
m_poFeatureDefn->GetFieldIndex("endTime") &&
poNode->papoSubExpr[1]->field_type == SWQ_TIMESTAMP )
{
int nTerms = GDALEEDALayerParseDateTime(poNode->papoSubExpr[1]->string_value,
SWQ_LE,
nYear, nMonth, nDay, nHour, nMinute, nSecond);
if( nTerms >= 3 )
{
if( poNode->nOperation == SWQ_EQ && nTerms == 6 )
{
m_bFilterMustBeClientSideEvaluated = true;
if( nSecond < 59 )
nSecond ++;
else if( nMinute < 59 )
nMinute ++;
else if( nHour < 23 )
nHour ++;
else
nDay ++;
}
m_osEndTime = CPLSPrintf("%04d-%02d-%02dT%02d:%02d:%02dZ",
nYear, nMonth, nDay, nHour, nMinute, nSecond);
}
else
{
m_bFilterMustBeClientSideEvaluated = true;
}
return "";
}
Expand Down

0 comments on commit 3506884

Please sign in to comment.