successfully export to png
This commit is contained in:
parent
2fbbc78233
commit
b515e40435
40
II/Referatas/layer2img.py
Executable file
40
II/Referatas/layer2img.py
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python3
|
||||
# https://gis.stackexchange.com/questions/131716/plot-shapefile-with-matplotlib
|
||||
|
||||
import argparse
|
||||
import geopandas
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
INCH = 25.4 # mm
|
||||
|
||||
def plt_size(string):
|
||||
if not string:
|
||||
return None
|
||||
try:
|
||||
w, h = string.split("x")
|
||||
return float(w) / INCH, float(h) / INCH
|
||||
except Exception as e:
|
||||
raise argparse.ArgumentTypeError from e
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description='Convert layer to an image')
|
||||
parser.add_argument('infile', type=str)
|
||||
parser.add_argument('layer', type=str)
|
||||
parser.add_argument('-o', '--output', metavar='<file>', type=str)
|
||||
parser.add_argument('--size', type=plt_size, help='Figure size in mm (WWxHH)')
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = parse_args()
|
||||
f = geopandas.read_file(args.infile)
|
||||
f.plot(figsize=args.size)
|
||||
plt.axis('off')
|
||||
plt.margins(0, 0)
|
||||
plt.tight_layout(0)
|
||||
if args.output:
|
||||
plt.savefig(args.output, bbox_inches=0, dpi=300)
|
||||
else:
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -1,16 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
# https://gis.stackexchange.com/questions/131716/plot-shapefile-with-matplotlib
|
||||
|
||||
import argparse
|
||||
import fiona
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Convert layer to a nice PDF')
|
||||
parser.add_argument('infile', type=argparse.FileType('r'))
|
||||
parser.add_argument('layer', type=str)
|
||||
parser.add_argument('-o', metavar='OUTFILE', type=argparse.FileType('w'))
|
||||
args = parser.parse_args()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user