# Parcel recalculation optimization
* enhances workflow for parcel recalculation
This commit is contained in:
		
							parent
							
								
									50f46e319c
								
							
						
					
					
						commit
						46a2a4ff46
					
				@ -34,7 +34,9 @@ class Command(BaseKonovaCommand):
 | 
				
			|||||||
    def recalculate_parcels(self, options: dict):
 | 
					    def recalculate_parcels(self, options: dict):
 | 
				
			||||||
        force_all = options.get("force_all", False)
 | 
					        force_all = options.get("force_all", False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        geometry_objects = Geometry.objects.all()
 | 
					        geometry_objects = Geometry.objects.all().exclude(
 | 
				
			||||||
 | 
					            geom=None
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not force_all:
 | 
					        if not force_all:
 | 
				
			||||||
            # Fetch all intersections
 | 
					            # Fetch all intersections
 | 
				
			||||||
@ -46,16 +48,17 @@ class Command(BaseKonovaCommand):
 | 
				
			|||||||
                "geometry__id",
 | 
					                "geometry__id",
 | 
				
			||||||
                flat=True
 | 
					                flat=True
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
            # Filter those geometries out (they have intersections and do not need to be processed)
 | 
					            intersected_geom_objs = Geometry.objects.filter(
 | 
				
			||||||
            geometry_objects = geometry_objects.exclude(
 | 
					 | 
				
			||||||
                id__in=geom_with_intersection_ids
 | 
					                id__in=geom_with_intersection_ids
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            # Filter those geometries out (they have intersections and do not need to be processed)
 | 
				
			||||||
 | 
					            geometry_objects = geometry_objects.difference(intersected_geom_objs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._write_warning("=== Update parcels and districts ===")
 | 
					        self._write_warning("=== Update parcels and districts ===")
 | 
				
			||||||
        # Order geometries by size to process smaller once at first
 | 
					        # Order geometries by size to process smaller once at first
 | 
				
			||||||
        geometries = geometry_objects.exclude(
 | 
					        geometries = geometry_objects.annotate(
 | 
				
			||||||
            geom=None
 | 
					            area=Area("geom")
 | 
				
			||||||
        ).annotate(area=Area("geom")).order_by(
 | 
					        ).order_by(
 | 
				
			||||||
            'area'
 | 
					            'area'
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...")
 | 
					        self._write_warning(f"Process parcels for {geometries.count()} geometry entries now ...")
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user