def digestNodesFromZIP(sourcePath):
    # Shape
    hasShapeFile, shapePath = store.unzip(sourcePath, ".shp")
    if not hasShapeFile:
        raise DatasetError("Archive does not contain a shapefile")
    # Digest
    return digestNodesFromSHP(shapePath)
Example #2
0
    def generateSegments(self, nodes, computeDistance, proj4):
        'Generate segment candidates connecting nodes to the existing grid'
        # Prepare
        segmentFactory = network.SegmentFactory(nodes, computeDistance, proj4)

        # Use more efficient CandidateManager for candidate segments
        candidateManager = CandidateManager(segmentFactory.getNodes(), computeDistance)

        net = network.Network(segmentFactory, useIndex=True)
        networkRelativePath = self.get(ExistingNetworks)
        # If we have existing networks,
        if networkRelativePath:
            # Reconstruct path
            networkArchivePath = os.path.join(self.state[0].getBasePath(), networkRelativePath)
            if not os.path.exists(networkArchivePath):
                raise variable_store.VariableError('Expected ZIP archive containing shapefile for existing networks')
            isValid, networkPath = store.unzip(networkArchivePath, 'shp')
            if not isValid:
                raise variable_store.VariableError('Could not find shapefile in ZIP archive for existing networks')
            # Load network
            networkProj4, networkGeometries = geometry_store.load(networkPath)[:2]
            networkCoordinatePairs = network.yieldSimplifiedCoordinatePairs(networkGeometries)
            # Prepare
            transform_point = geometry_store.get_transform_point(networkProj4, proj4)
            # Load existing network as a single subnet and allow overlapping segments
            net.addSubnet(network.Subnet([segmentFactory.getSegment(transform_point(c1[0], c1[1]), transform_point(c2[0], c2[1]), is_existing=True) for c1, c2 in networkCoordinatePairs]))
            # Add candidate segments that connect each node to its 
            # projection on the existing network
            projectedTuples = net.projectEfficient(candidateManager.nodes)
            candidateManager.extendNodeTuples(projectedTuples)

        return candidateManager, net 
Example #3
0
def digestNodesFromZIP(sourcePath):
    # Shape
    hasShapeFile, shapePath = store.unzip(sourcePath, '.shp')
    if not hasShapeFile:
        raise DatasetError('Archive does not contain a shapefile')
    # Digest
    return digestNodesFromSHP(shapePath)
Example #4
0
    def generateSegments(self, nodes, computeDistance, proj4):
        'Generate segment candidates connecting nodes to the existing grid'
        # Prepare
        segmentFactory = network.SegmentFactory(nodes, computeDistance, proj4)

        # Use more efficient CandidateManager for candidate segments
        candidateManager = CandidateManager(segmentFactory.getNodes(),
                                            computeDistance)

        net = network.Network(segmentFactory, useIndex=True)
        networkRelativePath = self.get(ExistingNetworks)
        # If we have existing networks,
        if networkRelativePath:
            # Reconstruct path
            networkArchivePath = os.path.join(self.state[0].getBasePath(),
                                              networkRelativePath)
            if not os.path.exists(networkArchivePath):
                raise variable_store.VariableError(
                    'Expected ZIP archive containing shapefile for existing networks'
                )
            isValid, networkPath = store.unzip(networkArchivePath, 'shp')
            if not isValid:
                raise variable_store.VariableError(
                    'Could not find shapefile in ZIP archive for existing networks'
                )
            # Load network
            networkProj4, networkGeometries = geometry_store.load(
                networkPath)[:2]
            networkCoordinatePairs = network.yieldSimplifiedCoordinatePairs(
                networkGeometries)
            # Prepare
            transform_point = geometry_store.get_transform_point(
                networkProj4, proj4)
            # Load existing network as a single subnet and allow overlapping segments
            net.addSubnet(
                network.Subnet([
                    segmentFactory.getSegment(transform_point(c1[0], c1[1]),
                                              transform_point(c2[0], c2[1]),
                                              is_existing=True)
                    for c1, c2 in networkCoordinatePairs
                ]))
            # Add candidate segments that connect each node to its
            # projection on the existing network
            projectedTuples = net.projectEfficient(candidateManager.nodes)
            candidateManager.extendNodeTuples(projectedTuples)

        return candidateManager, net
Example #5
0
 def generateSegments(self, nodes, computeDistance, proj4):
     'Generate segment candidates connecting nodes to the existing grid'
     # Prepare
     segments = []
     segmentFactory = network.SegmentFactory(nodes, computeDistance, proj4)
     networkNodes = segmentFactory.getNodes()
     net = network.Network(segmentFactory)
     networkRelativePath = self.get(ExistingNetworks)
     # If we have existing networks,
     if networkRelativePath:
         # Reconstruct path
         networkArchivePath = os.path.join(self.state[0].getBasePath(), networkRelativePath)
         if not os.path.exists(networkArchivePath):
             raise variable_store.VariableError('Expected ZIP archive containing shapefile for existing networks')
         isValid, networkPath = store.unzip(networkArchivePath, 'shp')
         if not isValid:
             raise variable_store.VariableError('Could not find shapefile in ZIP archive for existing networks')
         # Load network
         networkProj4, networkGeometries = geometry_store.load(networkPath)[:2]
         networkCoordinatePairs = network.yieldSimplifiedCoordinatePairs(networkGeometries)
         # Prepare
         transform_point = geometry_store.get_transform_point(networkProj4, proj4)
         # Load existing network as a single subnet and allow overlapping segments
         net.subnets.append(network.Subnet([segmentFactory.getSegment(transform_point(c1[0], c1[1]), transform_point(c2[0], c2[1]), is_existing=True) for c1, c2 in networkCoordinatePairs]))
         # Add candidate segments that connect each node to its projection on the existing network
         segments.extend(net.project(networkNodes))
     # Prepare matrix where the rows are nodes and the columns are node coordinates
     networkNodeMatrix = np.array([node.getCoordinates() for node in networkNodes])
     # Define get_nearestNeighbors()
     if computeDistance == network.computeEuclideanDistance:
         kdTree = KDTree(networkNodeMatrix)
     else:
         earthRadiusInMeters = 6371010
         kdTree = Arc_KDTree(networkNodeMatrix, radius=earthRadiusInMeters)
     get_nearestNeighbors = functools.partial(kdTree.query, k=self.get(MaximumNearestNeighborCount))
     # For each node,
     for node1 in networkNodes:
         # Get its nearest neighbors
         nodeIndices = get_nearestNeighbors(node1.getCoordinates())[1]
         # Add candidate segments from the node to each of its nearest neighbors
         for node2Coordinates in networkNodeMatrix[nodeIndices]:
             # Let getSegment() compute segment weight in case we want to customize how we weight each segment
             segments.append(segmentFactory.getSegment(node1.getCoordinates(), tuple(node2Coordinates)))
     # Return
     return segments, net