Skip to content

Commit

Permalink
Merge pull request #309 from satellogic/use-mask-band
Browse files Browse the repository at this point in the history
Add UseMaskBand option support
  • Loading branch information
drnextgis authored Oct 19, 2021
2 parents cf8993c + 23eac72 commit 1f056ef
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 52 deletions.
40 changes: 23 additions & 17 deletions telluric/base_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,29 +88,35 @@ def add_band(self, dtype, band_idx, color_interp,

return vrtrasterband

def add_band_simplesource(self, vrtrasterband, band_idx, dtype, relative_to_vrt,
file_name, rasterxsize, rasterysize, blockxsize=None, blockysize=None,
src_rect=None, dst_rect=None, nodata=None
):
simplesource = ET.SubElement(vrtrasterband, 'SimpleSource')
self._setup_band_simplesource(simplesource, band_idx, dtype, relative_to_vrt, file_name,
rasterxsize, rasterysize, blockxsize, blockysize, nodata)
srcrect_element = ET.SubElement(simplesource, 'SrcRect')
def add_band_complexsource(
self, vrtrasterband, band_idx, dtype, relative_to_vrt,
file_name, rasterxsize, rasterysize, blockxsize=None, blockysize=None,
src_rect=None, dst_rect=None, nodata=None
):
complexsource = ET.SubElement(vrtrasterband, 'ComplexSource')
self._setup_band_complexsource(
complexsource, band_idx, dtype, relative_to_vrt, file_name,
rasterxsize, rasterysize, blockxsize, blockysize, nodata)
srcrect_element = ET.SubElement(complexsource, 'SrcRect')
self._setup_rect(srcrect_element, src_rect.col_off, src_rect.row_off,
src_rect.width, src_rect.height)
dstrect_element = ET.SubElement(simplesource, 'DstRect')
dstrect_element = ET.SubElement(complexsource, 'DstRect')
self._setup_rect(dstrect_element, dst_rect.col_off, dst_rect.row_off,
dst_rect.width, dst_rect.height)
return simplesource, srcrect_element, dstrect_element

def _setup_band_simplesource(self, simplesource, band_idx, dtype, relative_to_vrt, file_name,
rasterxsize, rasterysize, blockxsize, blockysize, nodata):
sourcefilename = ET.SubElement(simplesource, 'SourceFilename')
usemaskband = ET.SubElement(complexsource, 'UseMaskBand')
usemaskband.text = 'true'
return complexsource, srcrect_element, dstrect_element

def _setup_band_complexsource(
self, complexsource, band_idx, dtype, relative_to_vrt, file_name,
rasterxsize, rasterysize, blockxsize, blockysize, nodata
):
sourcefilename = ET.SubElement(complexsource, 'SourceFilename')
sourcefilename.attrib['relativeToVRT'] = "1" if relative_to_vrt else "0"
sourcefilename.text = vsi_path(parse_path(file_name))
sourceband = ET.SubElement(simplesource, 'SourceBand')
sourceband = ET.SubElement(complexsource, 'SourceBand')
sourceband.text = str(band_idx)
sourceproperties = ET.SubElement(simplesource, 'SourceProperties')
sourceproperties = ET.SubElement(complexsource, 'SourceProperties')
sourceproperties.attrib['RasterXSize'] = str(rasterxsize)
sourceproperties.attrib['RasterYSize'] = str(rasterysize)
if blockxsize is not None and blockysize is not None:
Expand All @@ -123,7 +129,7 @@ def _setup_band_simplesource(self, simplesource, band_idx, dtype, relative_to_vr
# so till we figure it out I leave it commented out

# if nodata is not None:
# nodata_elem = ET.SubElement(simplesource, 'NODATA')
# nodata_elem = ET.SubElement(complexsource, 'NODATA')
# nodata_elem.text = str(nodata)

def _setup_rect(self, sub_element, xoff, yoff, xsize, ysize):
Expand Down
182 changes: 174 additions & 8 deletions telluric/gdalvrt.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="SRS" type="xs:string"/>
<xs:element name="SRS" type="SRSType"/>
<xs:element name="GeoTransform" type="xs:string"/>
<xs:element name="GCPList" type="GCPListType"/>
<xs:element name="BlockXSize" type="nonNegativeInteger32"/>
Expand All @@ -44,14 +44,36 @@
<xs:element name="MaskBand" type="MaskBandType"/>
<xs:element name="GDALWarpOptions" type="GDALWarpOptionsType"/> <!-- only if subClass="VRTWarpedDataset" -->
<xs:element name="PansharpeningOptions" type="PansharpeningOptionsType"/> <!-- only if subClass="VRTPansharpenedDataset" -->
<xs:element name="Group" type="GroupType"/> <!-- only for multidimensional dataset -->
<xs:element name="OverviewList" type="OverviewListType"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="subClass" type="xs:string"/>
<xs:attribute name="rasterXSize" type="nonNegativeInteger32" use="required"/>
<xs:attribute name="rasterYSize" type="nonNegativeInteger32" use="required"/>
<xs:attribute name="rasterXSize" type="nonNegativeInteger32"/>
<xs:attribute name="rasterYSize" type="nonNegativeInteger32"/>
</xs:complexType>
</xs:element>

<xs:complexType name="OverviewListType">
<xs:simpleContent>
<xs:extension base="integerList">
<xs:attribute name="resampling" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:simpleType name="integerList">
<xs:list itemType="xs:integer"/>
</xs:simpleType>

<xs:complexType name="SRSType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="dataAxisToSRSAxisMapping" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:simpleType name="nonNegativeInteger32">
<xs:restriction base="xs:nonNegativeInteger">
<xs:maxInclusive value="2147483647"/>
Expand All @@ -63,6 +85,7 @@
<xs:element name="GCP" type="GCPType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="Projection" type="xs:string"/>
<xs:attribute name="dataAxisToSRSAxisMapping" type="xs:string"/>
</xs:complexType>

<xs:complexType name="GCPType">
Expand Down Expand Up @@ -149,6 +172,7 @@
<xs:element name="Scale" type="xs:double"/>
<xs:element name="CategoryNames" type="CategoryNamesType"/>
<xs:element name="ColorTable" type="ColorTableType"/>
<xs:element name="GDALRasterAttributeTable" type="GDALRasterAttributeTableType"/>
<xs:element name="NoDataValue" type="DoubleOrNanType"/>
<xs:element name="NodataValue" type="xs:double"/> <!-- typo: deprecated -->
<xs:element name="HideNoDataValue" type="ZeroOrOne"/>
Expand Down Expand Up @@ -186,10 +210,9 @@
</xs:sequence>
<xs:attribute name="dataType" type="DataTypeType"/>
<xs:attribute name="band" type="xs:unsignedInt"/>
<xs:attribute name="blockXSize" type="nonNegativeInteger32"/>
<xs:attribute name="blockYSize" type="nonNegativeInteger32"/>
<xs:attribute name="subClass" type="VRTRasterBandSubClassType"/>

<xs:attribute name="BlockXSize" type="xs:unsignedInt"/> <!-- ignored -->
<xs:attribute name="BlockYSize" type="xs:unsignedInt"/> <!-- ignored -->
</xs:complexType>

<xs:simpleType name="ZeroOrOne">
Expand Down Expand Up @@ -245,6 +268,29 @@
</xs:sequence>
</xs:complexType>

<xs:complexType name="GDALRasterAttributeTableType">
<xs:sequence>
<xs:element name="FieldDefn" type="FieldDefnType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Row" type="RowType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="FieldDefnType">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Type" type="xs:unsignedInt"/>
<xs:element name="Usage" type="xs:unsignedInt"/>
</xs:sequence>
<xs:attribute name="index" type="xs:unsignedInt" use="required"/>
</xs:complexType>

<xs:complexType name="RowType">
<xs:sequence>
<xs:element name="F" type="xs:anyType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="index" type="xs:unsignedInt" use="required"/>
</xs:complexType>

<xs:complexType name="OverviewType">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
Expand Down Expand Up @@ -343,7 +389,8 @@
<xs:element name="SrcMax" type="xs:double"/>
<xs:element name="DstMin" type="xs:double"/>
<xs:element name="DstMax" type="xs:double"/>
<xs:element name="NODATA" type="DoubleOrNanType"/>
<xs:element name="NODATA" type="DoubleOrNanType"/> <!-- NODATA and UseMaskBand are mutually exclusive -->
<xs:element name="UseMaskBand" type="xs:boolean"/> <!-- NODATA and UseMaskBand are mutually exclusive -->
<xs:element name="LUT" type="xs:string"/>
</xs:choice>
</xs:sequence>
Expand Down Expand Up @@ -436,4 +483,123 @@
</xs:restriction>
</xs:simpleType>

</xs:schema>
<xs:complexType name="GroupType">
<xs:sequence>
<xs:element name="Dimension" type="DimensionType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Attribute" type="AttributeType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Array" type="ArrayType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="Group" type="GroupType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="ArrayType">
<xs:sequence>
<xs:element name="DataType" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Dimension" type="DimensionType"/>
<xs:element name="DimensionRef" type="DimensionRefType"/>
</xs:choice>
</xs:sequence>
<xs:element name="SRS" type="SRSType" minOccurs="0" maxOccurs="1"/>
<xs:element name="Unit" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="NoDataValue" type="DoubleOrNanType" minOccurs="0" maxOccurs="1"/>
<xs:element name="Offset" type="xs:double" minOccurs="0" maxOccurs="1"/>
<xs:element name="Scale" type="xs:double" minOccurs="0" maxOccurs="1"/>
<xs:choice>
<xs:element name="RegularlySpacedValues" type="RegularlySpacedValuesType" minOccurs="0" maxOccurs="1"/>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="ConstantValue" type="ConstantValueType"/>
<xs:element name="InlineValues" type="InlineValuesType"/>
<xs:element name="InlineValuesWithValueElement" type="InlineValuesWithValueElementType"/>
<xs:element name="Source" type="SourceType"/>
</xs:choice>
</xs:sequence>
</xs:choice>
<xs:element name="Attribute" type="AttributeType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="RegularlySpacedValuesType">
<xs:attribute name="start" type="xs:double" use="required"/>
<xs:attribute name="increment" type="xs:double" use="required"/>
</xs:complexType>

<xs:complexType name="ConstantValueType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="offset" type="xs:string"/>
<xs:attribute name="count" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="InlineValuesType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="offset" type="xs:string"/>
<xs:attribute name="count" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<xs:complexType name="InlineValuesWithValueElementType">
<xs:sequence>
<xs:element name="Value" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="offset" type="xs:string"/>
<xs:attribute name="count" type="xs:string"/>
</xs:complexType>

<xs:complexType name="SourceType">
<xs:sequence>
<xs:element name="SourceFilename" type="SourceFilenameType"/>
<xs:choice>
<xs:element name="SourceArray" type="xs:string"/>
<xs:element name="SourceBand" type="xs:string"/>
</xs:choice>
<xs:element name="SourceTranspose" type="xs:string" minOccurs="0"/>
<xs:element name="SourceView" type="xs:string" minOccurs="0"/>
<xs:element name="SourceSlab" type="SourceSlabType" minOccurs="0"/>
<xs:element name="DestSlab" type="DestSlabType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="SourceSlabType">
<xs:sequence/>
<xs:attribute name="offset" type="xs:string"/>
<xs:attribute name="count" type="xs:string"/>
<xs:attribute name="step" type="xs:string"/>
</xs:complexType>

<xs:complexType name="DestSlabType">
<xs:sequence/>
<xs:attribute name="offset" type="xs:string"/>
</xs:complexType>

<xs:complexType name="AttributeType">
<xs:sequence>
<xs:element name="DataType" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="Value" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>

<xs:complexType name="DimensionType">
<xs:sequence/>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="direction" type="xs:string"/>
<xs:attribute name="size" type="xs:nonNegativeInteger" use="required"/>
<xs:attribute name="indexingVariable" type="xs:string"/>
</xs:complexType>

<xs:complexType name="DimensionRefType">
<xs:sequence/>
<xs:attribute name="ref" type="xs:string" use="required"/>
</xs:complexType>

</xs:schema>
Loading

0 comments on commit 1f056ef

Please sign in to comment.