overlays
This commit is contained in:
parent
d1555091b4
commit
006debd28d
@ -38,7 +38,7 @@ sinewave.gpkg: fig2layer.py
|
|||||||
./fig2layer.py -o $@ sine
|
./fig2layer.py -o $@ sine
|
||||||
|
|
||||||
rectangle.gpkg: fig2layer.py
|
rectangle.gpkg: fig2layer.py
|
||||||
./fig2layer.py -o $@ rectangle --bounds $(CROSSING)
|
./fig2layer.py -o $@ rect --bounds $(CROSSING)
|
||||||
|
|
||||||
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
|
||||||
|
@ -25,41 +25,45 @@ def plt_size(string):
|
|||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Convert geopackage to an image')
|
description='Convert geopackage to an image')
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
ingroup = parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument('--infile', type=str)
|
ingroup.add_argument('--infile')
|
||||||
group.add_argument('--table', type=str)
|
ingroup.add_argument('--table')
|
||||||
parser.add_argument('-o', '--outfile', metavar='<file>', type=str)
|
parser.add_argument('-o', '--outfile', metavar='<file>')
|
||||||
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( '--clip', type=float, nargs=4, metavar=BOUNDS)
|
parser.add_argument( '--clip', type=float, nargs=4, metavar=BOUNDS)
|
||||||
parser.add_argument(
|
|
||||||
'--rect', type=float, nargs=4, help="Overlay a rectangle",
|
overlay = parser.add_mutually_exclusive_group()
|
||||||
metavar=BOUNDS)
|
overlay.add_argument('--overlay-infile', type=str)
|
||||||
|
overlay.add_argument('--overlay-table', type=str)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def read_layer(maybe_table, maybe_file):
|
||||||
|
if maybe_table:
|
||||||
|
conn = psycopg2.connect("host=127.0.0.1 dbname=osm user=osm")
|
||||||
|
sql = "SELECT geom FROM %s" % maybe_table
|
||||||
|
return geopandas.read_postgis(sql, con=conn, geom_col='geom')
|
||||||
|
elif maybe_file:
|
||||||
|
return geopandas.read_file(maybe_file)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.table:
|
primary = read_layer(args.table, args.infile)
|
||||||
conn = psycopg2.connect("host=127.0.0.1 dbname=osm user=osm")
|
overlay = read_layer(args.overlay_table, args.overlay_infile)
|
||||||
sql = "SELECT geom FROM %s" % args.table
|
|
||||||
f = geopandas.read_postgis(sql, con=conn, geom_col='geom')
|
|
||||||
else:
|
|
||||||
f = geopandas.read_file(args.infile)
|
|
||||||
|
|
||||||
rc('text', usetex=True)
|
rc('text', usetex=True)
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
if args.size:
|
if args.size:
|
||||||
fig.set_size_inches(args.size)
|
fig.set_size_inches(args.size)
|
||||||
f.plot(ax=ax)
|
primary.plot(ax=ax)
|
||||||
if c := args.clip:
|
if c := args.clip:
|
||||||
ax.set_xlim(left=c[0], right=c[2])
|
ax.set_xlim(left=c[0], right=c[2])
|
||||||
ax.set_ylim(bottom=c[1], top=c[3])
|
ax.set_ylim(bottom=c[1], top=c[3])
|
||||||
if r := args.rect:
|
|
||||||
w, h = r[2] - r[0], r[3] - r[1]
|
if overlay is not None:
|
||||||
rect = patches.Rectangle(
|
overlay.plot(ax=ax)
|
||||||
(r[0], r[1]), w, h, linewidth=1,edgecolor='r',facecolor='none')
|
|
||||||
ax.add_patch(rect)
|
|
||||||
|
|
||||||
ax.axis('off')
|
ax.axis('off')
|
||||||
ax.margins(0, 0)
|
ax.margins(0, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user