Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : JOSM Q Othogonalize for Predicted features #158

Merged
merged 1 commit into from
Aug 22, 2023
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
1 change: 1 addition & 0 deletions backend/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class PredictionParamSerializer(serializers.Serializer):
model_id = serializers.IntegerField(required=True)
zoom_level = serializers.IntegerField(required=True)
confidence = serializers.IntegerField(required=False)
use_josm_q = serializers.BooleanField(required=False)
source = serializers.URLField(required=False)

def validate(self, data):
Expand Down
1 change: 0 additions & 1 deletion backend/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def download_image(url, base_path, source_name):
response = requests.get(url)
image = response.content
url = re.sub(r"\.(png|jpeg)$", "", url)
logging.info(url)

url_splitted_list = url.split("/")
filename = f"{base_path}/{source_name}-{url_splitted_list[-2]}-{url_splitted_list[-1]}-{url_splitted_list[-3]}.png"
Expand Down
6 changes: 5 additions & 1 deletion backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from hot_fair_utilities import polygonize, predict, vectorize
from login.authentication import OsmAuthentication
from login.permissions import IsOsmAuthenticated
from orthogonalizer import othogonalize_poly
from osmconflator import conflate_geojson
from rest_framework import decorators, serializers, status, viewsets
from rest_framework.decorators import api_view
Expand Down Expand Up @@ -374,7 +375,7 @@ def ConflateGeojson(request):

conflated_geojson = conflate_geojson(geojson_data, remove_conflated=True)

return Response(conflated_geojson,status = 200)
return Response(conflated_geojson, status=200)


@api_view(["GET"])
Expand Down Expand Up @@ -501,6 +502,7 @@ def post(self, request, *args, **kwargs):
if res_serializer.is_valid(raise_exception=True):
deserialized_data = res_serializer.data
bbox = deserialized_data["bbox"]
use_josm_q = deserialized_data["use_josm_q"]
model_instance = get_object_or_404(Model, id=deserialized_data["model_id"])
if not model_instance.published_training:
return Response("Model is not published yet", status=404)
Expand Down Expand Up @@ -589,6 +591,8 @@ def post(self, request, *args, **kwargs):
for feature in geojson_data["features"]:
feature["properties"]["building"] = "yes"
feature["properties"]["source"] = "fAIr"
if use_josm_q is True:
feature["geometry"] = othogonalize_poly(feature["geometry"])

shutil.rmtree(temp_path)

Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ validators==0.20.0
gpxpy==1.5.0
hot-fair-utilities
geojson2osm==0.0.1
osmconflator==0.0.6
osmconflator==0.0.6
orthogonalizer==0.0.4
18 changes: 18 additions & 0 deletions frontend/src/components/Layout/Start/Prediction/Prediction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Button,
Grid,
Box,
Switch,
CircularProgress,
Paper,
Typography,
Expand Down Expand Up @@ -56,6 +57,10 @@ const Prediction = () => {

const [apiCallInProgress, setApiCallInProgress] = useState(false);
const [confidence, setConfidence] = useState(90);
const [use_josm_q, setUse_josm_q] = useState(true);
const handleUseJosmToggle = () => {
setUse_josm_q(!use_josm_q);
};
const [totalPredictionsCount, settotalPredictionsCount] = useState(0);
// const [DeletedCount, setDeletedCount] = useState(0);
// const [CreatedCount, setCreatedCount] = useState(0);
Expand Down Expand Up @@ -210,6 +215,7 @@ const Prediction = () => {
zoom_level: zoom,
source: dataset.source_imagery,
confidence: confidence,
use_josm_q: use_josm_q,
};
const startTime = new Date().getTime(); // measure start time
const res = await axios.post(`/prediction/`, body, { headers });
Expand Down Expand Up @@ -498,6 +504,7 @@ const Prediction = () => {
</Tooltip>
<FormControl size="small">
<Select
size="small"
value={confidence}
onChange={(e) => setConfidence(e.target.value)}
style={{ width: "80px", fontSize: "12px" }} // Adjust width and font size
Expand All @@ -511,6 +518,17 @@ const Prediction = () => {
</Select>
</FormControl>
</Box>
<Box display="flex" alignItems="center" mt={2}>
<Typography variant="body2" style={{ marginRight: "10px" }}>
<strong>Use JOSM Q: </strong>
</Typography>
<Switch
size="small"
checked={use_josm_q}
onChange={handleUseJosmToggle}
color="primary"
/>
</Box>
<Typography variant="body2">
<strong> Current Zoom:</strong> {JSON.stringify(zoom)}
</Typography>
Expand Down