|
32 | 32 | #include <mapnik/image_any.hpp> |
33 | 33 | #include <mapnik/value.hpp> |
34 | 34 | #include <mapnik/value/error.hpp> |
35 | | -#include <mapnik/scale_denominator.hpp> |
36 | 35 | #include <mapnik/label_collision_detector.hpp> |
37 | 36 | #include "mapnik_value_converter.hpp" |
38 | 37 | #include "python_to_value.hpp" |
@@ -436,32 +435,6 @@ void render_to_file3(mapnik::Map const& map, |
436 | 435 | } |
437 | 436 | } |
438 | 437 |
|
439 | | -double scale_denominator(mapnik::Map const& map, bool geographic) |
440 | | -{ |
441 | | - return mapnik::scale_denominator(map.scale(), geographic); |
442 | | -} |
443 | | - |
444 | | -// http://docs.python.org/c-api/exceptions.html#standard-exceptions |
445 | | -void value_error_translator(mapnik::value_error const & ex) |
446 | | -{ |
447 | | - PyErr_SetString(PyExc_ValueError, ex.what()); |
448 | | -} |
449 | | - |
450 | | -void runtime_error_translator(std::runtime_error const & ex) |
451 | | -{ |
452 | | - PyErr_SetString(PyExc_RuntimeError, ex.what()); |
453 | | -} |
454 | | - |
455 | | -void out_of_range_error_translator(std::out_of_range const & ex) |
456 | | -{ |
457 | | - PyErr_SetString(PyExc_IndexError, ex.what()); |
458 | | -} |
459 | | - |
460 | | -void standard_error_translator(std::exception const & ex) |
461 | | -{ |
462 | | - PyErr_SetString(PyExc_RuntimeError, ex.what()); |
463 | | -} |
464 | | - |
465 | 438 | // indicator for pycairo support in the python bindings |
466 | 439 | bool has_pycairo() |
467 | 440 | { |
@@ -675,7 +648,8 @@ PYBIND11_MODULE(_mapnik, m) { |
675 | 648 | export_shield_symbolizer(m); |
676 | 649 | export_group_symbolizer(m); |
677 | 650 | export_building_symbolizer(m); |
678 | | - |
| 651 | + // exceptions |
| 652 | + py::register_exception<mapnik::value_error>(m, "PyExc_MapnikValueError", PyExc_ValueError); |
679 | 653 | // |
680 | 654 | m.def("version", &mapnik_version,"Get the Mapnik version number"); |
681 | 655 | m.def("version_string", &mapnik_version_string,"Get the Mapnik version string"); |
@@ -708,6 +682,14 @@ PYBIND11_MODULE(_mapnik, m) { |
708 | 682 | py::arg("offset_x") = 0, |
709 | 683 | py::arg("offset_y") = 0); |
710 | 684 |
|
| 685 | + m.def("render_with_vars", &render_with_vars, |
| 686 | + py::arg("Map"), |
| 687 | + py::arg("image"), |
| 688 | + py::arg("vara"), |
| 689 | + py::arg("scale_factor") = 1.0, |
| 690 | + py::arg("offset_x") = 0, |
| 691 | + py::arg("offset_y") = 0); |
| 692 | + |
711 | 693 | m.def("render_with_detector", &render_with_detector, |
712 | 694 | py::arg("Map"), |
713 | 695 | py::arg("image"), |
@@ -912,302 +894,3 @@ PYBIND11_MODULE(_mapnik, m) { |
912 | 894 |
|
913 | 895 | m.def("has_pycairo", &has_pycairo, "Get pycairo module status"); |
914 | 896 | } |
915 | | - |
916 | | -// // stl |
917 | | -// #include <stdexcept> |
918 | | -// #include <fstream> |
919 | | - |
920 | | -// void export_color(); |
921 | | -// void export_composite_modes(); |
922 | | -// void export_coord(); |
923 | | -// void export_layer(); |
924 | | -// void export_parameters(); |
925 | | -// void export_envelope(); |
926 | | -// void export_query(); |
927 | | -// void export_geometry(); |
928 | | -// void export_palette(); |
929 | | -// void export_image(); |
930 | | -// void export_image_view(); |
931 | | -// void export_gamma_method(); |
932 | | -// void export_scaling_method(); |
933 | | -// #if defined(GRID_RENDERER) |
934 | | -// void export_grid(); |
935 | | -// void export_grid_view(); |
936 | | -// #endif |
937 | | -// void export_map(); |
938 | | -// void export_python(); |
939 | | -// void export_expression(); |
940 | | -// void export_rule(); |
941 | | -// void export_style(); |
942 | | -// void export_feature(); |
943 | | -// void export_featureset(); |
944 | | -// void export_fontset(); |
945 | | -// void export_datasource(); |
946 | | -// void export_datasource_cache(); |
947 | | -// void export_symbolizer(); |
948 | | -// void export_markers_symbolizer(); |
949 | | -// void export_point_symbolizer(); |
950 | | -// void export_line_symbolizer(); |
951 | | -// void export_line_pattern_symbolizer(); |
952 | | -// void export_polygon_symbolizer(); |
953 | | -// void export_building_symbolizer(); |
954 | | -// void export_placement_finder(); |
955 | | -// void export_polygon_pattern_symbolizer(); |
956 | | -// void export_raster_symbolizer(); |
957 | | -// void export_text_symbolizer(); |
958 | | -// void export_shield_symbolizer(); |
959 | | -// void export_debug_symbolizer(); |
960 | | -// void export_group_symbolizer(); |
961 | | -// void export_font_engine(); |
962 | | -// void export_projection(); |
963 | | -// void export_proj_transform(); |
964 | | -// void export_view_transform(); |
965 | | -// void export_raster_colorizer(); |
966 | | -// void export_label_collision_detector(); |
967 | | -// void export_logger(); |
968 | | - |
969 | | -// #include <mapnik/version.hpp> |
970 | | -// #include <mapnik/map.hpp> |
971 | | -// #include <mapnik/datasource.hpp> |
972 | | -// #include <mapnik/layer.hpp> |
973 | | -// #include <mapnik/agg_renderer.hpp> |
974 | | -// #include <mapnik/rule.hpp> |
975 | | -// #include <mapnik/image_util.hpp> |
976 | | -// #include <mapnik/image_any.hpp> |
977 | | -// #include <mapnik/load_map.hpp> |
978 | | -// #include <mapnik/value/error.hpp> |
979 | | -// #include <mapnik/value.hpp> |
980 | | -// #include <mapnik/save_map.hpp> |
981 | | -// #include <mapnik/scale_denominator.hpp> |
982 | | -// #if defined(GRID_RENDERER) |
983 | | -// #include "python_grid_utils.hpp" |
984 | | -// #endif |
985 | | -//#include "mapnik_value_converter.hpp" |
986 | | -// #include "mapnik_enumeration_wrapper_converter.hpp" |
987 | | -//#include "mapnik_threads.hpp" |
988 | | -// #include "python_optional.hpp" |
989 | | -// #include <mapnik/marker_cache.hpp> |
990 | | -// #if defined(SHAPE_MEMORY_MAPPED_FILE) |
991 | | -// #include <mapnik/mapped_memory_cache.hpp> |
992 | | -// #endif |
993 | | - |
994 | | -// #if defined(SVG_RENDERER) |
995 | | -// #include <mapnik/svg/output/svg_renderer.hpp> |
996 | | -// #endif |
997 | | - |
998 | | -// namespace mapnik { |
999 | | -// class font_set; |
1000 | | -// class layer; |
1001 | | -// class color; |
1002 | | -// class label_collision_detector4; |
1003 | | -// } |
1004 | | - |
1005 | | -// #if defined(HAVE_CAIRO) |
1006 | | -// #include <mapnik/cairo_io.hpp> |
1007 | | -// #include <mapnik/cairo/cairo_renderer.hpp> |
1008 | | -// #include <cairo.h> |
1009 | | -// #endif |
1010 | | - |
1011 | | -// #if defined(HAVE_PYCAIRO) |
1012 | | -// #include <boost/python/type_id.hpp> |
1013 | | -// #include <boost/python/converter/registry.hpp> |
1014 | | -// #if PY_MAJOR_VERSION >= 3 |
1015 | | -// #include <py3cairo.h> |
1016 | | -// #else |
1017 | | -// #include <pycairo.h> |
1018 | | -// static Pycairo_CAPI_t *Pycairo_CAPI; |
1019 | | -// #endif |
1020 | | - |
1021 | | -// static void *extract_surface(PyObject* op) |
1022 | | -// { |
1023 | | -// if (PyObject_TypeCheck(op, const_cast<PyTypeObject*>(Pycairo_CAPI->Surface_Type))) |
1024 | | -// { |
1025 | | -// return op; |
1026 | | -// } |
1027 | | -// else |
1028 | | -// { |
1029 | | -// return 0; |
1030 | | -// } |
1031 | | -// } |
1032 | | - |
1033 | | -// static void *extract_context(PyObject* op) |
1034 | | -// { |
1035 | | -// if (PyObject_TypeCheck(op, const_cast<PyTypeObject*>(Pycairo_CAPI->Context_Type))) |
1036 | | -// { |
1037 | | -// return op; |
1038 | | -// } |
1039 | | -// else |
1040 | | -// { |
1041 | | -// return 0; |
1042 | | -// } |
1043 | | -// } |
1044 | | - |
1045 | | -// void register_cairo() |
1046 | | -// { |
1047 | | -// #if PY_MAJOR_VERSION >= 3 |
1048 | | -// Pycairo_CAPI = (Pycairo_CAPI_t*) PyCapsule_Import(const_cast<char *>("cairo.CAPI"), 0); |
1049 | | -// #else |
1050 | | -// Pycairo_CAPI = (Pycairo_CAPI_t*) PyCObject_Import(const_cast<char *>("cairo"), const_cast<char *>("CAPI")); |
1051 | | -// #endif |
1052 | | -// if (Pycairo_CAPI == nullptr) return; |
1053 | | - |
1054 | | -// boost::python::converter::registry::insert(&extract_surface, boost::python::type_id<PycairoSurface>()); |
1055 | | -// boost::python::converter::registry::insert(&extract_context, boost::python::type_id<PycairoContext>()); |
1056 | | -// } |
1057 | | -// #endif |
1058 | | - |
1059 | | - |
1060 | | - |
1061 | | -// #pragma GCC diagnostic push |
1062 | | -// #pragma GCC diagnostic ignored "-Wunused-local-typedef" |
1063 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(load_map_overloads, load_map, 2, 4) |
1064 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(load_map_string_overloads, load_map_string, 2, 4) |
1065 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_overloads, save_map, 2, 3) |
1066 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(save_map_to_string_overloads, save_map_to_string, 1, 2) |
1067 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(render_overloads, render, 2, 5) |
1068 | | -// BOOST_PYTHON_FUNCTION_OVERLOADS(render_with_detector_overloads, render_with_detector, 3, 6) |
1069 | | -// #pragma GCC diagnostic pop |
1070 | | - |
1071 | | -// BOOST_PYTHON_MODULE(_mapnik) |
1072 | | -// { |
1073 | | - |
1074 | | -// using namespace boost::python; |
1075 | | - |
1076 | | -// using mapnik::load_map; |
1077 | | -// using mapnik::load_map_string; |
1078 | | -// using mapnik::save_map; |
1079 | | -// using mapnik::save_map_to_string; |
1080 | | - |
1081 | | -// register_exception_translator<std::exception>(&standard_error_translator); |
1082 | | -// register_exception_translator<std::out_of_range>(&out_of_range_error_translator); |
1083 | | -// register_exception_translator<mapnik::value_error>(&value_error_translator); |
1084 | | -// register_exception_translator<std::runtime_error>(&runtime_error_translator); |
1085 | | -// #if defined(HAVE_CAIRO) && defined(HAVE_PYCAIRO) |
1086 | | -// register_cairo(); |
1087 | | -// #endif |
1088 | | -// export_query(); |
1089 | | -// export_geometry(); |
1090 | | -// export_feature(); |
1091 | | -// export_featureset(); |
1092 | | -// export_fontset(); |
1093 | | -// export_datasource(); |
1094 | | -// export_parameters(); |
1095 | | -// export_color(); |
1096 | | -// export_composite_modes(); |
1097 | | -// export_envelope(); |
1098 | | -// export_palette(); |
1099 | | -// export_image(); |
1100 | | -// export_image_view(); |
1101 | | -// export_gamma_method(); |
1102 | | -// export_scaling_method(); |
1103 | | -// #if defined(GRID_RENDERER) |
1104 | | -// export_grid(); |
1105 | | -// export_grid_view(); |
1106 | | -// #endif |
1107 | | -// export_expression(); |
1108 | | -// export_rule(); |
1109 | | -// export_style(); |
1110 | | -// export_layer(); |
1111 | | -// export_datasource_cache(); |
1112 | | -// export_symbolizer(); |
1113 | | -// export_markers_symbolizer(); |
1114 | | -// export_point_symbolizer(); |
1115 | | -// export_line_symbolizer(); |
1116 | | -// export_line_pattern_symbolizer(); |
1117 | | -// export_polygon_symbolizer(); |
1118 | | -// export_building_symbolizer(); |
1119 | | -// export_placement_finder(); |
1120 | | -// export_polygon_pattern_symbolizer(); |
1121 | | -// export_raster_symbolizer(); |
1122 | | -// export_text_symbolizer(); |
1123 | | -// export_shield_symbolizer(); |
1124 | | -// export_debug_symbolizer(); |
1125 | | -// export_group_symbolizer(); |
1126 | | -// export_font_engine(); |
1127 | | -// export_projection(); |
1128 | | -// export_proj_transform(); |
1129 | | -// export_view_transform(); |
1130 | | -// export_coord(); |
1131 | | -// export_map(); |
1132 | | -// export_raster_colorizer(); |
1133 | | -// export_label_collision_detector(); |
1134 | | -// export_logger(); |
1135 | | - |
1136 | | - |
1137 | | -// def("render_tile_to_file",&render_tile_to_file, |
1138 | | -// "\n" |
1139 | | -// "TODO\n" |
1140 | | -// "\n" |
1141 | | -// ); |
1142 | | - |
1143 | | -// def("render_with_vars",&render_with_vars, |
1144 | | -// (arg("map"), |
1145 | | -// arg("image"), |
1146 | | -// arg("vars"), |
1147 | | -// arg("scale_factor")=1.0, |
1148 | | -// arg("offset_x")=0, |
1149 | | -// arg("offset_y")=0 |
1150 | | -// ) |
1151 | | -// ); |
1152 | | - |
1153 | | -// def("render", &render, render_overloads( |
1154 | | -// "\n" |
1155 | | -// "Render Map to an AGG image_any using offsets\n" |
1156 | | -// "\n" |
1157 | | -// "Usage:\n" |
1158 | | -// ">>> from mapnik import Map, Image, render, load_map\n" |
1159 | | -// ">>> m = Map(256,256)\n" |
1160 | | -// ">>> load_map(m,'mapfile.xml')\n" |
1161 | | -// ">>> im = Image(m.width,m.height)\n" |
1162 | | -// ">>> scale_factor=2.0\n" |
1163 | | -// ">>> offset = [100,50]\n" |
1164 | | -// ">>> render(m,im)\n" |
1165 | | -// ">>> render(m,im,scale_factor)\n" |
1166 | | -// ">>> render(m,im,scale_factor,offset[0],offset[1])\n" |
1167 | | -// "\n" |
1168 | | -// )); |
1169 | | - |
1170 | | -// def("render_with_detector", &render_with_detector, render_with_detector_overloads( |
1171 | | -// "\n" |
1172 | | -// "Render Map to an AGG image_any using a pre-constructed detector.\n" |
1173 | | -// "\n" |
1174 | | -// "Usage:\n" |
1175 | | -// ">>> from mapnik import Map, Image, LabelCollisionDetector, render_with_detector, load_map\n" |
1176 | | -// ">>> m = Map(256,256)\n" |
1177 | | -// ">>> load_map(m,'mapfile.xml')\n" |
1178 | | -// ">>> im = Image(m.width,m.height)\n" |
1179 | | -// ">>> detector = LabelCollisionDetector(m)\n" |
1180 | | -// ">>> render_with_detector(m, im, detector)\n" |
1181 | | -// )); |
1182 | | -// def("save_map_to_string", &save_map_to_string, save_map_to_string_overloads()); |
1183 | | -// def("mapnik_version", &mapnik_version,"Get the Mapnik version number"); |
1184 | | -// def("mapnik_version_string", &mapnik_version_string,"Get the Mapnik version string"); |
1185 | | -// def("has_proj", &has_proj, "Get proj status"); |
1186 | | -// def("has_jpeg", &has_jpeg, "Get jpeg read/write support status"); |
1187 | | -// def("has_png", &has_png, "Get png read/write support status"); |
1188 | | -// def("has_tiff", &has_tiff, "Get tiff read/write support status"); |
1189 | | -// def("has_webp", &has_webp, "Get webp read/write support status"); |
1190 | | -// def("has_svg_renderer", &has_svg_renderer, "Get svg_renderer status"); |
1191 | | -// def("has_grid_renderer", &has_grid_renderer, "Get grid_renderer status"); |
1192 | | -// def("has_cairo", &has_cairo, "Get cairo library status"); |
1193 | | -// def("has_pycairo", &has_pycairo, "Get pycairo module status"); |
1194 | | - |
1195 | | -// python_optional<mapnik::font_set>(); |
1196 | | -// python_optional<mapnik::color>(); |
1197 | | -// python_optional<mapnik::box2d<double> >(); |
1198 | | -// python_optional<mapnik::composite_mode_e>(); |
1199 | | -// python_optional<mapnik::datasource_geometry_t>(); |
1200 | | -// python_optional<std::string>(); |
1201 | | -// python_optional<unsigned>(); |
1202 | | -// python_optional<double>(); |
1203 | | -// python_optional<float>(); |
1204 | | -// python_optional<bool>(); |
1205 | | -// python_optional<int>(); |
1206 | | -// python_optional<mapnik::text_transform_e>(); |
1207 | | -// register_ptr_to_python<mapnik::expression_ptr>(); |
1208 | | -// register_ptr_to_python<mapnik::path_expression_ptr>(); |
1209 | | - |
1210 | | -// to_python_converter<mapnik::value_holder,mapnik_param_to_python>(); |
1211 | | -// to_python_converter<mapnik::value, mapnik_value_to_python>(); |
1212 | | -// to_python_converter<mapnik::enumeration_wrapper,mapnik_enumeration_wrapper_to_python>(); |
1213 | | -// } |
0 commit comments