diff --git a/II/Referatas/.gitignore b/II/Referatas/.gitignore index b981295..40fc8f8 100644 --- a/II/Referatas/.gitignore +++ b/II/Referatas/.gitignore @@ -1 +1,2 @@ sinewave.gpkg +rectangle.gpkg diff --git a/II/Referatas/Makefile b/II/Referatas/Makefile index d726e4f..b6ec0d4 100644 --- a/II/Referatas/Makefile +++ b/II/Referatas/Makefile @@ -34,8 +34,8 @@ $(eval $(call gpkg2pdf,sinewave,sinewave,--size=52x15)) $(eval $(call gpkg2pdf,zeimena,zeimena,--size=135x191 --rect $(CROSSING))) $(eval $(call gpkg2pdf,zeimena,crossing,--size=105x74 --clip $(CROSSING))) -sinewave.gpkg: sinewave.py - ./sinewave.py +sinewave.gpkg: fig2layer.py + ./fig2layer.py -o $@ sine db/.faux_ready: zeimena.gpkg sinewave.gpkg managedb -./managedb stop; rm -fr db diff --git a/II/Referatas/fig2layer.py b/II/Referatas/fig2layer.py new file mode 100755 index 0000000..c1ee237 --- /dev/null +++ b/II/Referatas/fig2layer.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +import argparse + +from math import pi +from pyproj import CRS +import numpy as np +import geopandas as gpd +from shapely.geometry import LineString, MultiLineString + +BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax') + + +def write_file(args, geom): + df = gpd.GeoDataFrame(crs=CRS(3346)) + df['geometry'] = None + df.loc[0, 'geometry'] = geom + df.to_file(args.outfile, driver='GPKG') + + +def sinewave(args): + INTERVAL = 0.1 + TAIL_LEN = 7 + SINE_LEN = 7 + TAILS = np.zeros(int(TAIL_LEN / INTERVAL)) + sin_range = np.arange(-pi/4, SINE_LEN, INTERVAL) + amplitude = (np.sin(sin_range * pi / 2) + 1)*2 + y = np.concatenate([TAILS, amplitude, TAILS]) + x = np.arange(-TAIL_LEN - pi/4, SINE_LEN + TAIL_LEN, INTERVAL) + lines = LineString(zip(x*10, y*10)) + geom = MultiLineString([lines]) + write_file(args, geom) + + +def rectangle(args): + line = LineString(( + (args.bounds[0], args.bounds[1]), + (args.bounds[0], args.bounds[3]), + (args.bounds[2], args.bounds[3]), + (args.bounds[2], args.bounds[1]), + (args.bounds[0], args.bounds[1]), + )) + write_file(args, MultiLineString([line])) + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('-o', '--outfile', metavar='', required=True) + subparsers = parser.add_subparsers() + sine = subparsers.add_parser('sine', help='Sine wave') + sine.set_defaults(func=sinewave) + rect = subparsers.add_parser('rect', help='Rectangle') + rect.add_argument('--bounds', type=float, nargs=4, metavar=BOUNDS) + rect.set_defaults(func=rectangle) + return parser.parse_args() + + +if __name__ == '__main__': + args = parse_args() + args.func(args) diff --git a/II/Referatas/layer2img.py b/II/Referatas/layer2img.py index cf17610..9d9b2b0 100755 --- a/II/Referatas/layer2img.py +++ b/II/Referatas/layer2img.py @@ -8,6 +8,7 @@ import matplotlib.pyplot as plt import matplotlib.patches as patches INCH = 25.4 # mm +BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax') def plt_size(string): @@ -29,12 +30,10 @@ def parse_args(): parser.add_argument('-o', '--outfile', metavar='', type=str) parser.add_argument( '--size', type=plt_size, help='Figure size in mm (WWxHH)') - parser.add_argument( - '--clip', type=float, nargs=4, - metavar=('xmin', 'ymin', 'xmax', 'ymax')) + parser.add_argument( '--clip', type=float, nargs=4, metavar=BOUNDS) parser.add_argument( '--rect', type=float, nargs=4, help="Overlay a rectangle", - metavar=('xmin', 'ymin', 'xmax', 'ymax')) + metavar=BOUNDS) return parser.parse_args() diff --git a/II/Referatas/sinewave.py b/II/Referatas/sinewave.py deleted file mode 100755 index 804cb56..0000000 --- a/II/Referatas/sinewave.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python -from math import pi -from pyproj import CRS -import numpy as np -import geopandas as gpd -from shapely.geometry import LineString, MultiLineString - -INTERVAL = 0.1 -TAIL_LEN = 7 -SINE_LEN = 7 - -TAILS = np.zeros(int(TAIL_LEN / INTERVAL)) - - -def main(): - sin_range = np.arange(-pi/4, SINE_LEN, INTERVAL) - amplitude = (np.sin(sin_range * pi / 2) + 1)*2 - y = np.concatenate([TAILS, amplitude, TAILS]) - x = np.arange(-TAIL_LEN - pi/4, SINE_LEN + TAIL_LEN, INTERVAL) - lines = LineString(zip(x*10, y*10)) - geom = MultiLineString([lines]) - df = gpd.GeoDataFrame(crs=CRS(3346)) - df['geometry'] = None - df.loc[0, 'geometry'] = geom - df.to_file("sinewave.gpkg", driver='GPKG') - - -if __name__ == '__main__': - main()