diff --git a/II/Referatas/layer2img.py b/II/Referatas/layer2img.py new file mode 100755 index 0000000..f50ffa5 --- /dev/null +++ b/II/Referatas/layer2img.py @@ -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='', 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() diff --git a/II/Referatas/layer2pdf.py b/II/Referatas/layer2pdf.py deleted file mode 100755 index 0fb2626..0000000 --- a/II/Referatas/layer2pdf.py +++ /dev/null @@ -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()