Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions docs/developers/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ psql -U postgres -d oldinsurancemaps -c "CREATE EXTENSION PostGIS;"
Run migrations and create admin user to access the Django admin panel (and login to the site once it's running)

```bash
python manage.py migrate
python manage.py createsuperuser
uv run manage.py migrate
uv run manage.py createsuperuser
```

Load a few other fixtures with some default objects:

```bash
python manage.py loaddata default-region-categories
python manage.py loaddata default-layerset-categories
python manage.py loaddata default-navbar
uv run manage.py loaddata default-region-categories
uv run manage.py loaddata default-layerset-categories
uv run manage.py loaddata default-navbar
```

Alternatively, if you have set all of the `DATABASE_*` variables in `.env`, you can use the included script to perform all of the actions described above:
Expand All @@ -125,7 +125,7 @@ source ./scripts/load_dev_data.sh
There are a few js and css plugins that must be downloaded to the local static directory:

```bash
python manage.py get-plugins
uv run manage.py get-plugins
```

The frontend uses a suite of independently built svelte components. First install `pnpm`: https://pnpm.io/installation. Then:
Expand Down Expand Up @@ -153,7 +153,7 @@ In production, use the `build` command instead, and then Django's `collectstatic
```bash
pnpm run build
cd ../../..
python manage.py collectstatic --noinput
uv run manage.py collectstatic --noinput
```

This bash script combines all steps into one:
Expand All @@ -168,7 +168,7 @@ You can now activate the virtual environment and then run the django dev server:

```bash
source .venv/bin/activate
python manage.py runserver
uv run manage.py runserver
```

and view the site at `http://localhost:8000`.
Expand Down Expand Up @@ -259,21 +259,21 @@ In production, you will already be using a webserver for static files so you wil
All tests are stored in `ohmg/tests`. Make sure you have installed dev requirements, then run:

```bash
python manage.py test
uv run manage.py test
```

To skip the tests that make external calls to the LOC API, use the following command. Keep in mind that coverage numbers will be lower when you skip tests.

```bash
python manage.py test --exclude-tag=loc
uv run manage.py test --exclude-tag=loc
```

## Load the Place scaffolding

Load all the place objects to create geography scaffolding (this will take a minute or two)

```bash
python manage.py place import-all
uv run manage.py place import-all
```

## Environment variables
Expand Down
2 changes: 1 addition & 1 deletion ohmg/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# set BASE_DIR which is used to locate log, cache, temp, static, and uploaded dirs
BASE_DIR = PROJECT_DIR.parent

# the build file is generated and updated with python manage.py update_build
# the build file is generated and updated with ./manage.py update_build
BUILD_FILE = BASE_DIR / ".build"
BUILD_NUMBER = ""
if BUILD_FILE.is_file():
Expand Down
43 changes: 22 additions & 21 deletions ohmg/extensions/iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ def get_target(self):
wgs84.ImportFromEPSG(4326)
mask_geojson = json.loads(self.layer.mask.geojson)
coords = mask_geojson["coordinates"][0]
ct = CoordTransform(SpatialReference("WGS84"), SpatialReference("EPSG:3857"))

target_crs = f"EPSG:{self.region.gcpgroup.crs_epsg}"
ct = CoordTransform(SpatialReference("WGS84"), SpatialReference(target_crs))
polygon = Polygon(coords)
polygon.transform(ct)

g = Georeferencer(
crs=f"EPSG:{self.region.gcpgroup.crs_epsg}",
transformation=self.region.gcpgroup.transformation,
gcps_geojson=self.region.gcpgroup.as_geojson,
)
in_path = (
self.region.file.url
if self.region.file.url.startswith("http")
else self.region.file.path
)

g = Georeferencer(
crs=target_crs,
transformation=self.region.gcpgroup.transformation,
gcps_geojson=self.region.gcpgroup.as_geojson,
)
g.make_gcps_vrt(in_path)
ds = gdal.Open(g.gcps_vrt.get_vsi_url())
transformer = gdal.Transformer(
# Source datasource
None,
# Target datasource
ds,
# Target datasource
None,
# Transformer options that are ultimately passed to 'GDALCreateGenImgProjTransformer2()'
# https://gdal.org/api/gdal_alg.html#_CPPv432GDALCreateGenImgProjTransformer212GDALDatasetH12GDALDatasetHPPc
[
## need to update this, different number if thin plate spline
"MAX_GCP_ORDER=1",
],
g.make_transformer_options(),
)
transposed, status = transformer.TransformPoints(False, polygon.coords[0])
transposed, status = transformer.TransformPoints(True, polygon.coords[0])
coords_str = [f"{i[0]},{i[1]}" for i in transposed]

coords_join = " ".join(coords_str)
Expand Down Expand Up @@ -114,14 +114,15 @@ def get_gcps(self):
return features

def get_body(self):
if self.region.gcpgroup.transformation == "poly1":
transformation = {"type": "polynomial", "options": {"order": 1}}
elif self.region.gcpgroup.transformation == "tps":
transformation = {
"type": "thinPlateSpline",
}
else:
raise Exception("invalid transformation", self.region.gcpgroup.transformation)
match t := self.region.gcpgroup.transformation:
case "poly1":
transformation = {"type": "polynomial", "options": {"order": 1}}
case "tps":
transformation = {"type": "thinPlateSpline"}
case "helmert":
transformation = {"type": "helmert"}
case _:
raise Exception(f"invalid transformation: {t}")

body = {
"id": full_reverse("iiif_gcps_view", args=(self.layerid,)),
Expand Down
2 changes: 1 addition & 1 deletion ohmg/extensions/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import path, register_converter

from ohmg.extensions.feeds import PlaceFeed
from ohmg.places.converters import PlaceConverter

from .views import (
Expand All @@ -9,7 +10,6 @@
IIIFResourceView,
IIIFSelectorView,
)
from ohmg.extensions.feeds import PlaceFeed

register_converter(PlaceConverter, "place-slug")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,6 @@
available: CONTEXT.user.perms.includes("core.use_helmert")
},
];
$: {
if (gcpList.length == 3 && currentTransformation == "helmert") {
currentTransformation = "poly1"
}
if (currentTransformation == "helmert") {
minGCPs = 2;
} else {
minGCPs = 3;
}
}
$: {
if (gcpList.length <= 2 && currentTransformation != "helmert") {
previewMode = "n/a"
}
}

let currentTargetProjection = 'EPSG:3857';
const availableProjections = [
Expand Down Expand Up @@ -590,6 +575,19 @@
note: props.note,
});
});

// special handling for helmert, do this before the preview is regenerated
if (gcpList.length == 3 && currentTransformation == "helmert") {
currentTransformation = "poly1";
}
if (currentTransformation == "helmert") {
minGCPs = 2;
} else {
minGCPs = 3;
}
if (gcpList.length <= 2 && currentTransformation != "helmert") {
previewMode = "n/a"
}
getPreview();
}

Expand Down Expand Up @@ -736,6 +734,16 @@
return featureCollection;
};

const preparePayload = function () {
return {
gcp_geojson: asGeoJSON(),
transformation: currentTransformation,
projection: currentTargetProjection,
sesh_id: sessionId,
last_preview_id: currentPreviewId,
}
}

function getPreview() {
if (currentTransformation == "helmert") {
minGCPs = 2;
Expand All @@ -750,13 +758,7 @@
`/georeference/${REGION.id}/`,
CONTEXT.ohmg_post_headers,
'preview',
{
gcp_geojson: asGeoJSON(),
transformation: currentTransformation,
projection: currentTargetProjection,
sesh_id: sessionId,
last_preview_id: currentPreviewId,
},
preparePayload(),
(result) => {
previewMode = previewMode == 'n/a' ? 'transparent' : previewMode;
// updating this variable will trigger the preview layer to be
Expand All @@ -779,13 +781,7 @@
`/georeference/${REGION.id}/`,
CONTEXT.ohmg_post_headers,
'submit',
{
gcp_geojson: asGeoJSON(),
transformation: currentTransformation,
projection: currentTargetProjection,
sesh_id: sessionId,
last_preview_id: currentPreviewId,
},
preparePayload(),
() => {
window.location.href = `/map/${REGION.map}`;
},
Expand Down Expand Up @@ -901,17 +897,23 @@
}}
on:unload={cancelSession}
/>
<div style="height:25px;">
Create 3 or more ground control points to georeference this document. <Link
<div>
Create three or more ground control points to georeference this document. First, click on a recognizable spot
in the document on the left to begin the GCP. Then, click on that same location in the web map on the right
to complete it. Learn more about the process <Link
href="https://docs.oldinsurancemaps.net/guides/georeferencing/"
external={true}>Learn more</Link
>
external={true}>in the docs</Link
>.
</div>

<ModalConfirm id="modal-submit-helmert" yesAction={submitSession}>
<ModalConfirm id="modal-submit-helmert"
yesButtonText="Submit with two GCPs"
yesAction={submitSession}
noButtonText="Back to georeferencing"
>
<p>
You have only two GCPs, but it is highly advisable to have three or more.
Please add more, unless you are unable to do so.
You have only created two GCPs, but we recommend having three or more.
If possible, please add more before submitting your work.
</p>
</ModalConfirm>
<ModalConfirm id="modal-cancel"
Expand Down
Loading