Agri fixes (#12033)
* crop_cycle, moving point in geojson from js to py * crop fields are fetched into crop_cycle - fixes #12011 * area is a readonly field - fixes #11994 * [agri] land unit child geojson bug fixed * set_intro null if parent field entered, list only group nodes * minor fixes
This commit is contained in:
parent
2a9dc9019a
commit
eb8446f01f
@ -15,7 +15,7 @@ frappe.ui.form.on('Crop Cycle', {
|
||||
output[doctype].forEach( (analysis_doc) => {
|
||||
let point_to_be_tested = JSON.parse(analysis_doc.location).features[0].geometry.coordinates;
|
||||
let poly_of_land = JSON.parse(land_doc.location).features[0].geometry.coordinates[0];
|
||||
if (test_analysis_position(point_to_be_tested, poly_of_land)){
|
||||
if (is_in_land_unit(point_to_be_tested, poly_of_land)){
|
||||
obj_to_append[analysis_doctypes_docs[analysis_doctypes.indexOf(doctype)]].push(analysis_doc.name);
|
||||
}
|
||||
});
|
||||
@ -28,7 +28,7 @@ frappe.ui.form.on('Crop Cycle', {
|
||||
}
|
||||
});
|
||||
|
||||
function test_analysis_position(point, vs) {
|
||||
function is_in_land_unit(point, vs) {
|
||||
// ray-casting algorithm based on
|
||||
// http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
|
||||
|
||||
|
@ -12,6 +12,10 @@ class CropCycle(Document):
|
||||
if self.is_new():
|
||||
crop = frappe.get_doc('Crop', self.crop)
|
||||
self.create_project(crop.period, crop.agriculture_task)
|
||||
if not self.crop_spacing_uom:
|
||||
self.crop_spacing_uom = crop.crop_spacing_uom
|
||||
if not self.row_spacing_uom:
|
||||
self.row_spacing_uom = crop.row_spacing_uom
|
||||
if not self.project:
|
||||
self.project = self.name
|
||||
for detected_disease in self.detected_disease:
|
||||
@ -59,4 +63,19 @@ class CropCycle(Document):
|
||||
return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('coordinates')
|
||||
|
||||
def get_geometry_type(self, doc):
|
||||
return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
|
||||
return ast.literal_eval(doc.location).get('features')[0].get('geometry').get('type')
|
||||
|
||||
def is_in_land_unit(self, point, vs):
|
||||
x, y = point
|
||||
inside = False
|
||||
j = len(vs)-1
|
||||
i = 0
|
||||
while i < len(vs):
|
||||
xi, yi = vs[i]
|
||||
xj, yj = vs[j]
|
||||
intersect = ((yi > y) != (yj > y)) and (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
|
||||
if intersect:
|
||||
inside = not inside
|
||||
i = j
|
||||
j += 1
|
||||
return inside
|
@ -9,6 +9,13 @@ frappe.ui.form.on('Land Unit', {
|
||||
setup: function(frm) {
|
||||
frm.add_fetch("parent_land_unit", "latitude", "latitude");
|
||||
frm.add_fetch("parent_land_unit", "longitude", "longitude");
|
||||
frm.set_query("parent_land_unit", function() {
|
||||
return {
|
||||
"filters": {
|
||||
"is_group": 1
|
||||
}
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
onload_post_render(frm){
|
||||
@ -28,4 +35,7 @@ frappe.ui.form.on('Land Unit', {
|
||||
frm.set_intro(null);
|
||||
}
|
||||
},
|
||||
parent_land_unit: function(frm) {
|
||||
frm.set_intro(null);
|
||||
},
|
||||
});
|
||||
|
@ -431,7 +431,7 @@
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
@ -632,7 +632,7 @@
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2017-12-13 16:50:18.581137",
|
||||
"modified": "2017-12-14 18:16:15.124188",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Agriculture",
|
||||
"name": "Land Unit",
|
||||
@ -680,7 +680,7 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 0,
|
||||
"quick_entry": 1,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 1,
|
||||
|
@ -10,6 +10,7 @@ import math
|
||||
from frappe import _
|
||||
|
||||
from frappe.utils.nestedset import NestedSet
|
||||
from frappe.utils import flt
|
||||
# from frappe.model.document import Document
|
||||
|
||||
RADIUS = 6378137
|
||||
@ -39,10 +40,10 @@ class LandUnit(NestedSet):
|
||||
else:
|
||||
features = json.loads(self.get('location')).get('features')
|
||||
new_area = compute_area(features)
|
||||
self.area_difference = new_area - self.area
|
||||
self.area_difference = new_area - flt(self.area)
|
||||
self.area = new_area
|
||||
|
||||
if self.get('parent'):
|
||||
if self.get('parent_land_unit'):
|
||||
ancestors = self.get_ancestors()
|
||||
self_features = self.add_child_property()
|
||||
self_features = set(self_features)
|
||||
@ -118,7 +119,7 @@ def compute_area(features):
|
||||
layer_area += polygon_area(coords = feature.get('geometry').get('coordinates'))
|
||||
elif feature.get('geometry').get('type') == 'Point' and feature.get('properties').get('point_type') == 'circle':
|
||||
layer_area += math.pi * math.pow(feature.get('properties').get('radius'), 2)
|
||||
return layer_area
|
||||
return flt(layer_area)
|
||||
|
||||
def rad(angle_in_degrees):
|
||||
return angle_in_degrees*math.pi/180
|
||||
|
@ -8,8 +8,8 @@ frappe.treeview_settings["Land Unit"] = {
|
||||
click: function(node) {
|
||||
var lu = frappe.new_doc("Land Unit", {
|
||||
"parent_land_unit": node.label
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user