def read(self): self.fields = shp.get_all_fields(self.from_file) for index, name in shp.get_numeric_attribute_names(self.from_file): self.numeric_fields.append((index, name)) if self.shape_type in (3, 5): self.read_line() elif self.shape_type in (13, 15): self.read_linez() else: self.read_linem()
def read(self): self.fields = shp.get_all_fields(self.from_file) self.numeric_fields = shp.get_numeric_attribute_names(self.from_file) if self.shape_type == 8: self.read_point() elif self.shape_type == 18: try: self.read_pointz() except RuntimeError: raise RuntimeError else: self.read_pointm() if not self.shapes: raise ValueError
def read(self): self.fields = shp.get_all_fields(self.from_file) for index, name in shp.get_numeric_attribute_names(self.from_file): self.numeric_fields.append((index, name)) if self.shape_type == 1: self.read_point() elif self.shape_type == 11: try: self.read_pointz() except RuntimeError: raise RuntimeError else: self.read_pointm() if not self.shapes: raise ValueError
def polygon_event(self): filename, _ = QFileDialog.getOpenFileName(self, 'Open a .shp file', '', 'Polygon file (*.shp)', options=QFileDialog.Options() | QFileDialog.DontUseNativeDialog) if not filename: return if not test_open(filename): return polygons = [] try: for polygon in Shapefile.get_polygons(filename): polygons.append(polygon) except struct.error: QMessageBox.critical(self, 'Error', 'Inconsistent bytes.', QMessageBox.Ok) return if not polygons: QMessageBox.critical(self, 'Error', 'The file does not contain any polygon.', QMessageBox.Ok) return items = ['%d - %s' % (index, name) for (index, name) in Shapefile.get_numeric_attribute_names(filename)] if not items: QMessageBox.critical(self, 'Error', 'The polygons do not have numeric attributes.', QMessageBox.Ok) return dlg = AttributeDialog(items) if dlg.exec_() != QDialog.Accepted: return attribute_index, attribute_name = dlg.attribute_box.currentText().split(' - ') attribute_index = int(attribute_index) short_name = os.path.join(os.path.basename(filename), os.path.split(filename)[1]) row = self.polygon_table.rowCount() self.polygon_table.insertRow(row) self.polygon_table.setItem(row, 0, QTableWidgetItem('POLY%d' % (row+1))) self.polygon_table.setItem(row, 1, QTableWidgetItem(attribute_name)) self.polygon_table.setItem(row, 2, QTableWidgetItem(short_name)) self.parent.editor_tab.pool.add_polygonal_mask(polygons, attribute_index)