我有一个XML文件链接:https://drive.google.com/file/d/1G0qtDY6HY9x7HQLY3vEmlba8cxLym5sw/view?usp=sharing
我要删除X =“-3.276700000000E + 04”和Y =“-3.276700000000E + 04”的行。该块如下所示:
<GCPList Projection="GEOGCS["WGS
84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]">
<GCP Id="" Pixel="0.5000" Line="0.5000" X="-8.887793731689E+01" Y="4.566011428833E+01" />
<GCP Id="" Pixel="260.5000" Line="0.5000" X="-8.877786254883E+01" Y="4.566171646118E+01" />
<GCP Id="" Pixel="520.5000" Line="0.5000" X="-8.867778015137E+01" Y="4.566323089600E+01" />...
<GCP Id="" Pixel="3640.5000" Line="7347.5000" X="-3.276700000000E+04" Y="-3.276700000000E+04" />
<GCP Id="" Pixel="3900.5000" Line="7347.5000" X="-3.276700000000E+04" Y="-3.276700000000E+04" />
<GCP Id="" Pixel="4160.5000" Line="7347.5000" X="-3.276700000000E+04" Y="-3.276700000000E+04" />
<GCP Id="" Pixel="4420.5000" Line="7347.5000" X="-3.276700000000E+04" Y="-3.276700000000E+04" />
</GCPList>
我想删除这些代码行并更新文件。
我写的代码是:
file = ET.parse('input6.vrt')
root = file.getroot()
for item in root.findall('.//trigger/GCPList'):
check_req_elems = elem.find('./@X=-32767]' and './@Y=-32767')
check_elem = elem.find('./@X=-32767]' and './@Y=-32767')
if check_req_elems is not None and check_elem is not None:
elem.remove(check_elem)
但是,这似乎并未对该文件进行任何更改。