add rectangle

This commit is contained in:
Motiejus Jakštys 2020-05-27 10:20:03 +03:00
parent a06c884cb1
commit 97cd7a5807
5 changed files with 65 additions and 35 deletions

View File

@ -1 +1,2 @@
sinewave.gpkg sinewave.gpkg
rectangle.gpkg

View File

@ -34,8 +34,8 @@ $(eval $(call gpkg2pdf,sinewave,sinewave,--size=52x15))
$(eval $(call gpkg2pdf,zeimena,zeimena,--size=135x191 --rect $(CROSSING))) $(eval $(call gpkg2pdf,zeimena,zeimena,--size=135x191 --rect $(CROSSING)))
$(eval $(call gpkg2pdf,zeimena,crossing,--size=105x74 --clip $(CROSSING))) $(eval $(call gpkg2pdf,zeimena,crossing,--size=105x74 --clip $(CROSSING)))
sinewave.gpkg: sinewave.py sinewave.gpkg: fig2layer.py
./sinewave.py ./fig2layer.py -o $@ sine
db/.faux_ready: zeimena.gpkg sinewave.gpkg managedb db/.faux_ready: zeimena.gpkg sinewave.gpkg managedb
-./managedb stop; rm -fr db -./managedb stop; rm -fr db

59
II/Referatas/fig2layer.py Executable file
View File

@ -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='<file>', 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)

View File

@ -8,6 +8,7 @@ import matplotlib.pyplot as plt
import matplotlib.patches as patches import matplotlib.patches as patches
INCH = 25.4 # mm INCH = 25.4 # mm
BOUNDS = ('xmin', 'ymin', 'xmax', 'ymax')
def plt_size(string): def plt_size(string):
@ -29,12 +30,10 @@ def parse_args():
parser.add_argument('-o', '--outfile', metavar='<file>', type=str) parser.add_argument('-o', '--outfile', metavar='<file>', type=str)
parser.add_argument( parser.add_argument(
'--size', type=plt_size, help='Figure size in mm (WWxHH)') '--size', type=plt_size, help='Figure size in mm (WWxHH)')
parser.add_argument( parser.add_argument( '--clip', type=float, nargs=4, metavar=BOUNDS)
'--clip', type=float, nargs=4,
metavar=('xmin', 'ymin', 'xmax', 'ymax'))
parser.add_argument( parser.add_argument(
'--rect', type=float, nargs=4, help="Overlay a rectangle", '--rect', type=float, nargs=4, help="Overlay a rectangle",
metavar=('xmin', 'ymin', 'xmax', 'ymax')) metavar=BOUNDS)
return parser.parse_args() return parser.parse_args()

View File

@ -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()